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/

相关文章:

powershell - 创建新插槽时更改 WebApp AppSetting 值

Azure Cosmos 图形数据库支持 Gremlin 和 Tinkerpop 版本

azure - 使用同一帐户 + Azure 应用程序网关的多个用户登录的 session 值更改

microsoft-translator - 如何调用 https ://api. datamarket.azure.com/Services/My/Datasets 获取 ResourceBalance

perl - 如何在 Perl 或 PowerShell 脚本中访问文件属性的 "Details"("Title"、 "Subject"等)

windows - 升级到 Windows 10 后,从批处理文件调用 powershell.exe 速度慢得无法忍受

localization - bing 翻译器语言代码 zh-CN 或 zh-CHS

java - Microsoft翻译API,Translate.execute()方法在android中不调用

powershell - 使用脚本 block 远程调用Get-Process

linux - 无法导入容器镜像错误 fabric_e_invalid_operation