在发送SOAP请求作为HTTP POST时没有获得SOAPAction头错误

时间:2014-04-16 16:59:48

标签: xml web-services soap soapui

由于某些项目限制,我在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>

有人能建议我在这里做些什么吗?

7 个答案:

答案 0 :(得分:15)

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

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

答案 1 :(得分:4)

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

答案 2 :(得分:1)

如果要发布API,则必须添加SOAPActionadd

postman image

答案 3 :(得分: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()

答案 4 :(得分:0)

// Delphi

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

答案 5 :(得分:0)

在我的情况下(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

答案 6 :(得分:0)

要获取SOAPAction,我们可以转到SOAP UI请求-> Raw。在请求中使用它并应完成工作

enter image description here