I'm trying to use Powershells Invoke-Webrequest to send a soap envelope to a password protected web service. The password contains the '£' char, which is causing the following error:
Invoke-WebRequest ...The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:password. The InnerException message was 'There was an error deserializing the object of type System.String. '�inthemiddle' contains invalid UTF8 bytes.'. Please see InnerException for more details.</faultstring></s:Fault></s:Body></s:Envelope>
This is the script (sensitive information removed):
[xml]$SOAP = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:MethodName>
<tem:password>passwordtextwit£inthemiddle</tem:password>
</tem:MethodName>
</soapenv:Body>
</soapenv:Envelope>'
$headers = @{"SOAPAction" = "http://tempuri.org/service/MethodName"}
$URI = "https://<MY URI.com>/service.svc"
$out = Invoke-WebRequest $uri -Method post -ContentType 'text/xml' -Body $SOAP -Headers $headers
It doesnt seem to matter what type/encoding I force the $SOAP to be, Invoke-Webrequest insists on interpreting the '£' as a '�'.
Any ideas?