【发布时间】:2015-06-13 08:14:43
【问题描述】:
我正在尝试使用 Powershells Invoke-Webrequest 将肥皂信封发送到受密码保护的 Web 服务。密码包含“£”字符,导致以下错误:
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>
这是脚本(敏感信息已删除):
[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
我强制 $SOAP 使用什么类型/编码似乎并不重要,Invoke-Webrequest 坚持将“£”解释为“�”。
有什么想法吗?
【问题讨论】:
-
您的脚本文件本身是 unicode 还是 utf-8 编码的?
-
它是由代理动态生成的(不是我写的)-但是如果我将输出粘贴到 ISE 中,我会遇到同样的问题,所以无论 Windows 2012 R2 上的 ISE 编码如何(PS 4.0) 默认我猜。
标签: xml powershell soap encoding