【发布时间】:2015-12-03 04:18:26
【问题描述】:
此 VBScript 将 XML 文档发布到 webService:
Dim xmlhttp, oXML, sourceURL, WSURL, WSUserName, WSPassword, XMLResponse
sourceURL = "C:\temp\myFileName.xml"
WSURL = "https://mywebServiceURL"
WSUserName = "myUserName"
WSPassword = "myPassword"
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.load(sourceURL)
xmlhttp.open "POST", WSURL, false, WSUserName, WSPassword
xmlhttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded; charset=UTF-8"
xmlhttp.setRequestHeader "Content-length", Len(oXML.xml)
xmlhttp.setRequestHeader "Connection", "close"
xmlhttp.setRequestHeader "soapAction", "processRequest"
'removes the head node and replaces it with a node which forces utf-8.
'Setting encoding headers simply does not work!!
dim repText, sXML, fXML
repText = "<?xml version=""1.0""?>"
fXML = replace(oXML.xml, repText, "")
sXML = "<?xml version=""1.0"" encoding=""utf-8""?>"
xmlhttp.send(sXML & fXML)
writeLog "XML len = " & Len(sXML & fXML)
writeLog "readyState = " & xmlhttp.readyState
If(xmlhttp.readyState = 4) then
WSStatus = xmlhttp.status
writeLog "WSStatus = " & WSStatus
WSResponse = xmlhttp.responseText
writeLog "WSResponse = " & WSResponse
WSResponse = xmlhttp.responseBody
writeLog "WSResponseBody = " & WSResponseBody
else
writeLog "ERROR : readyState = " & xmlhttp.readyState & " : "
end if
没有错误,一切似乎都很好。长度是正确的,readyState 是 4 但是 WS 返回 HTTP 409。返回的自定义消息是 'inbound not ok encoding="UTF-8" is missing'
这意味着该节点缺少 encoding="utf-8"?然而它不是。它的100%在那里。 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<ORDERS05>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM><![CDATA[EDI_DC40]]></TABNAM>
<IDOCTYP>aaa</IDOCTYP>
<MESTYP>sss</MESTYP>
<SNDPOR>ddd</SNDPOR>
</EDI_DC40>
</IDOC>
</ORDERS05>
这是来自 webService 人员的日志跟踪的开始。注意
POST /dir/anotherDir HTTP/1.1
content-type: application/x-www-form-urlencoded; charset=UTF-8
connection: close
soapaction: processRequest
accept-language: en-au
content-length: 4699
accept: */*
user-agent: Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
host: test.aURLHere.co.nz
clientprotocol: https
ssl_cipher_usekeysize: 128
ssl_cipher_suite: 0005
<?xml version="1.0"?>
<ORDERS05>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM><![CDATA[EDI_DC40]]></TABNAM>
<IDOCTYP>aaa</IDOCTYP>
<MESTYP>bbb</MESTYP>
<SNDPOR>ccc</SNDPOR>
我的发送可能有问题,或者这可能被 webService 丢弃了???非常坚持这一点。是发件人的问题还是收件人的问题?
编辑 - 我已经确定这是我的问题而不是接收者。注意添加到上面的代码中:
writelog(left(oXML.xml, 100))
它显示了我发送的 XML 的前 100 个字符。它从这个开始:
?xml 版本="1.0"?
即使这样:
?xml 版本=“1.0”编码=“utf-8”?
在 XML 文件中为 100%。这样做时如何丢弃它:
Set oXML = CreateObject("Microsoft.XMLDOM")
oXML.load(sourceURL)
编辑:所以解决方案是 WhiteHat 的建议。它的实现是上面添加的七行代码,开始(包括)注释“删除头节点和”
【问题讨论】:
-
你能解决吗?
-
感谢您的帖子。这些天,我试图在 w-ends 中保持 100 离线。请找到我对 OP 及以下内容的更新。我不确定追加然后查找/替换是最优雅的解决方案,但它确实有效。再次感谢
标签: xml web-services utf-8 vbscript asp-classic