Send a custom header of soap envelope using jQuery Ajax

后端 未结 2 1672
独厮守ぢ
独厮守ぢ 2021-01-14 06:54

I am trying to call an asmx service using jQuery Ajax.

POST /YderWS.asmx HTTP/1.1
Host: localhost
Content-Type: text/         


        
相关标签:
2条回答
  • 2021-01-14 07:14

    jQuery.ajax() issues generic HTTP requests for any type of "web service", not just .NET web services. You'll want to add a SOAPAction request header and pass the entire SOAP envelope as POST data:

    $.ajax({
        type: 'POST',
        url: servicename + "/" + functionName,
        contentType: 'text/xml; charset=utf-8',
        headers: {
            SOAPAction: 'http://scandihealth.com/iwebservices/HentKommuner'
        },
        data: '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><AuthHeader xmlns="http://scandihealth.com/iwebservices/"><PartnerID>string</PartnerID><SubPartnerID>string</SubPartnerID><SubPartnerType>string</SubPartnerType></AuthHeader></soap:Header><soap:Body><HentKommuner xmlns="http://scandihealth.com/iwebservices/" /></soap:Body></soap:Envelope>',
        success: successFn,
        error: errorFn
    });
    

    If you're using jQuery < 1.5, you'll need to use beforeSend to set the SOAPAction request header.

    You can find the documentation for jQuery.ajax() at http://api.jquery.com/jQuery.ajax/.

    0 讨论(0)
  • 2021-01-14 07:23

    Seems like you missed to add these:

    contentType: 'text/xml; charset=utf-8',
    dataType: 'xml'
    

    After adding these 2 lines it works fine for me debugging it with Selenium.

    0 讨论(0)
提交回复
热议问题