对此有任何帮助将不胜感激;我已经在这几天了。
以下是我到目前为止的代码;不幸的是,当我运行它时,我收到HTTP 415错误; 无法处理邮件,因为内容类型为'text / xml; charset = UTF-8'不是预期的类型'application / soap + xml;字符集= UTF-8'
我必须发送application / soap + xml的内容类型,因为这是web服务允许的唯一类型;我必须在经典的ASP中做到这一点。
我已尝试将“发送”行更改为“objRequest.send objXMLDoc.XML”,但这会给我一个 HTTP 400错误请求 错误。
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.createobject("MSXML2.XMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml"
objRequest.setRequestHeader "CharSet", "utf-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
Set objXMLDoc = Server.createobject("MSXML2.DOMDocument.3.0")
objXMLDoc.loadXml strXmlToSend
objRequest.send objXMLDoc
set objXMLDoc = nothing
答案 0 :(得分:3)
当您传递XML DOM或发送方法时,Content-Type始终设置为“text / xml”。
如果要控制内容类型,则必须传递字符串。不要只是为了调用xml属性而将XML字符串加载到DOM中,因为这可能会改变xml声明的内容。 BTW xml声明在XML字符串中是什么样的,你确定xml是正确的吗? xml声明的编码如果存在应该说“UTF-8”。
不发送标头CharSet
它没有任何意义,CharSet是Content-Type标头的属性。
不要在ASP内部使用XMLHTTP,这是不安全的。
因此,您的代码应该如下所示: -
strXmlToSend = "<some valid xml>"
webserviceurl = "http://webservice.com"
webserviceSOAPActionNameSpace = "avalidnamespace"
Set objRequest = Server.Createobject("MSXML2.ServerXMLHTTP.3.0")
objRequest.open "POST", webserviceurl, False
objRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=UTF-8"
objRequest.setRequestHeader "action", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.setRequestHeader "SOAPAction", webserviceSOAPActionNameSpace & "GetEstimate"
objRequest.send strXmlToSend
不确定那个“动作”标题对我来说看起来很棒。也许这仍然会以某种方式失败,但它不应该再抱怨Content-Type标题了。
答案 1 :(得分:2)
以下是我过去成功使用的内容:
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlhttp.open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SOAPAction", "http://www.mydomain.com/myaction"
xmlhttp.send postdata
xml = xmlhttp.responseText