Powershell-invoke-webrequest mit xml soap-envelope-body mit £ char Fehler

Ich versuche, Powershells Invoke-Webrequest senden einer soap-envelope zu einem Kennwort-geschützten web-service. Das Passwort enthält '£' char, was ist, verursacht den folgenden Fehler:

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>

Dies ist das Skript (sensible Informationen entfernt):

[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

Es scheint nicht zu Rolle, welche Art/encoding Kraft, die $SOAP, Invoke-Webrequest besteht auf die Interpretation der '£' als '�'.

Irgendwelche Ideen?

Ist die script-Datei selbst, unicode oder utf-8 kodiert?
Seine generiert on-the-fly durch einen bevollmächtigten (nicht von mir geschrieben) - aber wenn ich mir die Ausgabe und das einfügen in ISE ich habe das gleiche problem, so was auch immer Codierung ISE auf Windows 2012 R2 (PS 4.0) standardmäßig an, denke ich.

InformationsquelleAutor ItsNotMyStrongPoint | 2015-04-08

Schreibe einen Kommentar