powershell - 无法在 PowerShell 中找到类型 [System.Web.HttpUtility]

标签 powershell azure microsoft-translator

我尝试使用 PowerShell 获取 Microsoft Translator 应用程序的访问 token ,但该过程中的某些命令因错误而失败:

Unable to find type [System.Web.HttpUtility]

在收到此错误之前,我复制并粘贴了 this MSDN page 中的代码进入 PowerShell ISE,并将占位符值替换为我的实际凭据:

# ...
$ClientID = '<Your Value Here From Registered Application>'
$client_Secret = ‘<Your Registered Application client_secret>'

# If ClientId or Client_Secret has special characters, UrlEncode before sending request
$clientIDEncoded = [System.Web.HttpUtility]::UrlEncode($ClientID)
$client_SecretEncoded = [System.Web.HttpUtility]::UrlEncode($client_Secret)
# ...

我需要添加哪些额外代码才能使其正常工作?

最佳答案

您需要加载System.Web程序集。像这样使用 Add-Type cmdlet,

PS C:\> [System.Web.HttpUtility]::UrlEncode("www.google.com")
Unable to find type [System.Web.HttpUtility].

PS C:\> Add-Type -AssemblyName System.Web
PS C:\> [System.Web.HttpUtility]::UrlEncode("www.google.com")
www.google.com

关于powershell - 无法在 PowerShell 中找到类型 [System.Web.HttpUtility],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408729/

相关文章:

python - Python 中的微软翻译 API

powershell - 仅在进程运行时执行

powershell - 查找最新文件名并复制为同一文件夹中的重命名文件

sql-server - 如何在PowerShell中解析模棱两可的类型名称?

Azure:从现有 VHD 创建 VM 会产生 VMMarketplaceInvalidInput

java - 将 Microsoft Translator 与 Java/Jersey/REST 一起使用

powershell - 反序列化对象类型问题 - 特别是 Powershell 5 类和 Import-CliXml

asp.net-mvc - 续订 Azure ACS 颁发的 JWT

azure - 如何从视频中提取图像作为 Azure 媒体服务 v3 中编码的一部分?

java - Microsoft Translator API 检索翻译时出错