我正在尝试使用 New-WebServiceProxy cmdlet 创建 SOAP 服务的代理,用户名包含@
字符:
$webAddr = 'https://MYSERVER?wsdl'
$secpasswd = ConvertTo-SecureString "MYPASSWORD" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("USER@NAME", $secpasswd)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$proxy = New-WebServiceProxy -Uri $webAddr -Credential $mycreds
不知何故,这不起作用,我收到以下错误:
New-WebServiceProxy : 请求失败,HTTP 状态为 401: 身份验证失败!.
当我将相同的代码与没有"@"字符的用户名一起使用时,代理将被创建并且工作正常。当我在 Visual Studio 中添加服务引用或使用浏览器添加服务引用时,我还能够使用包含@
字符C#
的用户名连接到服务器。
我已经尝试使用System.Uri.EscapeUriString()
和System.Web.HttpUtility.UrlPathEncode()
转义用户名,但没有成功。
有什么想法吗?
好的,如果你告诉它没有域,它将假设@是用户名的一部分:
$mycreds = New-Object System.Management.Automation.PSCredential ("USER@NAME", $secpasswd)
添加 \ 就可以解决问题。