在使用HTTP POST发送SOAP请求时,出现了“未获取到SOAPAction头”错误

29

由于一些项目限制,我正在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>
尽管我已经设置了SOAPAction头,但仍然收到“没有SOAPAction头”错误消息。
响应如下:
<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>

有人能建议一下我们在这里可以做什么吗?


在你的WSDL中查找类似于<soap:operation soapAction="http://example.com/GetLastTradePrice"/>的行。对于“HelpDesk_Query_Service”操作,soapAction等于什么? - Abhishek Asthana
8个回答

25

看起来您正在发送一个不正确的soapAction头。查看WSDL并找出要测试的服务的soapAction元素的值。

在WSDL中寻找类似于<soap:operation soapAction="http://example.com/GetLastTradePrice"/>的行。


9

如果使用POST API,您需要添加 SOAPAction: add

postman image


7
request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );

创建一个 HttpWebRequest,然后添加头信息:code Dim bs = Encoding.UTF8.GetBytes("soap") Dim wr As HttpWebRequest = HttpWebRequest.Create("xx") wr.Headers.Add("ur soap hdr", "xxx") wr.ContentType = "text/xml; charset=utf-8" wr.Method = "POST" wr.ContentLength = bs.Length Dim sds As Stream = wr.GetRequestStream() sds.Write(bs, 0, bs.Length) sds.Close() Dim wr As WebResponse = wr.GetResponse() sds = wr.GetResponseStream() Dim sr As StreamReader = New StreamReader(sds) Dim strResult As String = sr.ReadToEnd() txtResult.Text = strResult sds.Close() sr.Close() wr.Close() code - Manpreet Singh Dhillon

5
只需将空引号作为参数添加到请求头中的SOAPAction参数即可。

enter image description here


2
在我的情况下,我不知道(wsdl)是什么,我只有终端点URL。以下代码片段适用于我执行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)

注意:'soapaction': 'http://myendpoint/url' 是必须的,以消除no SOAPAction header

0

我尝试在ynneh建议的答案中添加评论,但代码无法阅读。 他的答案很有用,但太短了。

创建一个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()

0

要获取SOAPAction,我们可以进入SOAP UI请求->原始。在请求中使用它,应该就可以完成工作了

enter image description here


-1

// Delphi

var
 xmlhttp : IXMLHTTPRequest; // unit MSXML2_TLB
begin
 xmlhttp := CoXMLHTTP.Create;
 xmlhttp.open('POST', Edit7.Text, False, EmptyParam, EmptyParam);
 xmlhttp.setRequestHeader('SOAPAction','POST')

SOAPAction的值在技术上并不是错误的,但会让读者对HTTP方法产生歧义。-1 - fartwhif

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接