我尝试使用 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/