I try to create a PSCredential
object with a password that contains german umlauts and pass it to the New-WebServiceProxy
cmdlet. The code works as expected as long as the password doesn't contain any umlauts like in the following example:
$secp = ConvertTo-SecureString 'abÜ312!' -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential('\user@db', $secp)
$proxy = New-WebServiceProxy -Uri "https://example.com/webservice/myWs?wsdl" -Credential $mycreds
In this case, I get the following error message:
New-WebServiceProxy : The request failed with HTTP status 401: Unauthorized.
When I capture the traffic using e. g. Fiddler, I see that the New-WebServiceProxy
cmdlet is adding the credentials as Basic Authorization with a base64 encoding:
GET https://example.com/webservice/myWs?wsdl HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 4.0.30319.42000)
Authorization: Basic dXNlckBkYjphYtwzMTIh
Host: example.com
This is how the decoded Base64 string looks like in Utf8:
So it looks like PowerShell is encoding the Umlauts as an ANSI string. When I manually base64 encode the Credentials (dXNlckBkYjphYsOcMzEyIQ==
instead of dXNlckBkYjphYtwzMTIh
) and reply the fiddler request, I get the desired response.
Unfortunately, I am not able to use this workaround because the New-WebServiceProxy
doesn't allow me to add the Authorization header myself.
Any ideas?