xml 将 SOAP 请求作为 HTTP POST 发送时没有出现 SOAPAction 标头错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23115697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting no SOAPAction header error in sending a SOAP request as HTTP POST
提问by Arun
I am sending a SOAP Request as HTTP POST in SOAPUI due to some project constraints. My Request is here :
由于某些项目限制,我在 SOAPUI 中将 SOAP 请求作为 HTTP POST 发送。我的请求在这里:
POST httplink HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:HPD_IncidentInterface_WS/HelpDesk_Query_Service"
Content-Length: 725
Host: itsm-mt-dev
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:HPD_IncidentInterface_WS">
<soapenv:Header>
<urn:AuthenticationInfo>
<urn:userName>XXXXXXXXXX</urn:userName>
<urn:password>XXXXXXXXX</urn:password>
<!--Optional:-->
<urn:authentication>?</urn:authentication>
<!--Optional:-->
<urn:locale>?</urn:locale>
<!--Optional:-->
<urn:timeZone>?</urn:timeZone>
</urn:AuthenticationInfo>
</soapenv:Header>
<soapenv:Body>
<urn:HelpDesk_Query_Service>
<urn:Incident_Number>XXXXXXXXXX</urn:Incident_Number>
</urn:HelpDesk_Query_Service>
</soapenv:Body>
</soapenv:Envelope>
Although I had set SOAPAction header, still I am getting no SOAPAction header error.
尽管我已经设置了 SOAPAction 标头,但我仍然没有收到 SOAPAction 标头错误。
Response as follows:
响应如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Client.NoSOAPAction</faultcode>
<faultstring>no SOAPAction header!</faultstring>
<detail>
<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">itsm-mt-dev</ns2:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Can anyone suggest me what we can do here ?
有人可以建议我在这里做什么吗?
回答by Abhishek Asthana
It looks like you are sending an incorrect soapAction header. Look at the WSDL and find out the value for soapAction element for the service being tested.
您发送的soapAction 标头似乎不正确。查看 WSDL 并找出被测试服务的 soapAction 元素的值。
In the WSDL look for a line similar to <soap:operation soapAction="http://example.com/GetLastTradePrice"/>.
在 WSDL 中查找类似于<soap:operation soapAction="http://example.com/GetLastTradePrice"/>.
回答by ynneh
request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );
回答by Shiva Prasad Adirala
In my case (wsdl) is unknown, and I have only end point url. Following snippet worked for me to perform soap api xml import:
在我的情况下(wsdl)是未知的,我只有终点网址。以下代码段对我执行soap api xml导入有用:
import requests
xml = """<mysoapxml>"""
# here "http://myendpoint/url" is service url (not a wsdl)
headers = {
'content-type': "text/xml; charset=utf-8",
'soapaction': 'http://myendpoint/url'
}
resp = requests.post('http://myendpoint/url', data=xml, headers=headers).text
print(resp)
Note: 'soapaction': 'http://myendpoint/url'is mandatory to eliminate no SOAPAction header
注:'soapaction': 'http://myendpoint/url'必须消除no SOAPAction header
回答by Vishal
回答by Manpreet Singh Dhillon
I tried to add comment in the answer suggested by ynneh but the code was not readable. His answer is useful but is too short.
我试图在 ynneh 建议的答案中添加评论,但代码不可读。他的回答很有用,但太短了。
Create a httpwebrequest and then add headers to it. following is complete example:
创建一个 httpwebrequest,然后向其中添加标头。以下是完整示例:
Dim bytSoap = System.Text.Encoding.UTF8.GetBytes("soap content")
Dim wrRequest As HttpWebRequest = HttpWebRequest.Create("xxxxx")
wrRequest.Headers.Add("your soap header", "xxx")
wrRequest.ContentType = "text/xml; charset=utf-8"
wrRequest.Method = "POST"
wrRequest.ContentLength = bytSoap.Length
Dim sDataStream As Stream = wrRequest.GetRequestStream()
sDataStream.Write(bytSoap, 0, bytSoap.Length)
sDataStream.Close()
Dim wrResponse As WebResponse = wrRequest.GetResponse()
sDataStream = wrResponse.GetResponseStream()
Dim srReader As StreamReader = New StreamReader(sDataStream)
Dim strResult As String = srReader.ReadToEnd()
txtResult.Text = strResult
sDataStream.Close()
srReader.Close()
wrResponse.Close()
回答by Vadim
// Delphi
// 德尔福
var
xmlhttp : IXMLHTTPRequest; // unit MSXML2_TLB
begin
xmlhttp := CoXMLHTTP.Create;
xmlhttp.open('POST', Edit7.Text, False, EmptyParam, EmptyParam);
xmlhttp.setRequestHeader('SOAPAction','POST')


