使用经典ASP发送"application/soap + xml" SOAP请求 [英] Sending a 'application/soap+xml' SOAP request using Classic ASP
问题描述
任何对此的帮助将不胜感激;我已经呆了几天了.
Any help with this would be appreciated; I've been at it for a few days now.
下面是到目前为止我得到的代码;不幸的是,当我运行它时,出现HTTP 415错误; 由于内容类型为'text/xml ;,因此无法处理该消息; charset = UTF-8'不是预期的类型'application/soap + xml; charset = utf-8' .
Below is the code that I've got so far; unfortunatly when I run it I get a HTTP 415 error; Cannot process the message because the content type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'.
我必须发送application/soap + xml的内容类型,因为这是Web服务允许的唯一类型;而且我必须使用经典的ASP来完成.
I have to send the content-type of application/soap+xml as this is the only type that the web service allows; and I have to do it in classic ASP.
我尝试将'send'行更改为"objRequest.send objXMLDoc.XML",但这会给我一个 HTTP 400错误请求 错误.>
I've tried changing the 'send' line to "objRequest.send objXMLDoc.XML" but this then gives me a HTTP 400 Bad Request error.
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
推荐答案
在传递XML DOM或send方法时,Content-Type始终设置为"text/xml".
When you pass an XML DOM ot the send method the Content-Type is always set to "text/xml".
如果要控制内容类型,则必须传递一个字符串.不要只为了调用xml属性而将XML字符串加载到DOM中,因为这可能会更改xml声明的内容.顺便说一句,XML声明在XML字符串中看起来像什么,您确定xml是正确的吗? xml上的编码声明(如果存在)应显示"UTF-8".
If you want to control the content type then you must pass a string. Don't bother loading the XML string into a DOM only to call the xml property since that may change the content of the xml declaration. BTW what does the xml declaration look like in the XML string and are you certain that the xml is correct? The encoding on the xml declare if present should say "UTF-8".
不发送标头CharSet
,它没有任何意义,CharSet是Content-Type标头的属性.
Don't send a header CharSet
it means nothing, CharSet is an attribute of the Content-Type header.
不要在ASP内部使用XMLHTTP,这是不安全的.
Don't use XMLHTTP from inside ASP its not safe.
因此,您的代码应如下所示:-
Hence your code ought to look like this:-
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标头.
Not sure about that "action" header either looks superflous to me. Perhaps this will still fail in some way but it shouldn't complain about the Content-Type header anymore.
这篇关于使用经典ASP发送"application/soap + xml" SOAP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!