Simplest SOAP example

前端 未结 13 1647
死守一世寂寞
死守一世寂寞 2020-11-22 01:32

What is the simplest SOAP example using Javascript?

To be as useful as possible, the answer should:

  • Be functional (in other words actually work)
  • <
13条回答
  •  终归单人心
    2020-11-22 01:57

    Angularjs $http wrap base on XMLHttpRequest. As long as at the header content set following code will do.

    "Content-Type": "text/xml; charset=utf-8"
    

    For example:

    function callSoap(){
    var url = "http://www.webservicex.com/stockquote.asmx";
    var soapXml = " "+
             " "+
             " "+
             " "+
             " "+
             " "+
             " "+
             " ";
    
        return $http({
              url: url,  
              method: "POST",  
              data: soapXml,  
              headers: {  
                  "Content-Type": "text/xml; charset=utf-8"
              }  
          })
          .then(callSoapComplete)
          .catch(function(message){
             return message;
          });
    
        function callSoapComplete(data, status, headers, config) {
            // Convert to JSON Ojbect from xml
            // var x2js = new X2JS();
            // var str2json = x2js.xml_str2json(data.data);
            // return str2json;
            return data.data;
    
        }
    
    }
    

提交回复
热议问题