Encoding “<” and “>” while sending XML via HTTP Post

别来无恙 提交于 2019-12-13 01:53:45

问题


I am sending an XML content via HTTP Post from Access VBA to Web Methods, using XMLHTTP object in MSXML. Here is the Code.

Dim objXmlHttp As Object
Set objXmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
objXmlHttp.Open "POST", webServicePath, False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

Dim Response As String
objXmlHttp.send wrt.output

'OK status
If objXmlHttp.Status = 200 Then
    Response = objXmlHttp.responseText
End If
Set objXmlHttp = Nothing

I am getting the XML with "&lt" and "&gt" instead of < and >. If I try to do URL encoding, everything is received as ASCII text in the Recipient side. Can you please guide what I need to do to get the valid XML format.


回答1:


You need to set the content-type correctly, try this instead:

objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=""utf-8"""


来源:https://stackoverflow.com/questions/1406470/encoding-and-while-sending-xml-via-http-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!