How to correctly post a WS SOAP with Ajax?

0

I have a WS (SOAP) with a connection to mysql developed in netbeans with a single method called SearchClient, that when doing the tester, you enter name and return the age. I want to consume it via Ajax by sending a SOAP message with this code.

 <div id="demo"></div>
 <script type="text/javascript">
  var xmlhttp;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  xmlhttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  var sr= '<?xml version="1.0" encoding="UTF-8"?>'+'<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">'+
  ' <SOAP-ENV:Header/>'+ 
  '<S:Body>'+
  '<ns2:BuscarClienteResponse xmlns:ns2="http://WebServ/">'+
  '<arg0>Leslie</arg0>'+
  '</ns2:BuscarClienteResponse>'+
  '</S:Body>'+
  '</S:Envelope>';

 xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
  document.getElementById("demo").innerHTML = this.responseText;
    }
  };
   xmlhttp.open("POST","http://localhost:8080/WSoap/Servicio?WSDL",true);

   xmlhttp.send(sr);

   </script>  

But I have the following problem when doing the post as is the code, checking through Fiddler it appears:

POST / WSoap / Service? WSDL HTTP / 1.1 in the Request and HTTP / 1.1 415 Unsupported Media Type in the Response

but when you put the header:

xmlhttp.setRequestHeader ("Content-Type", "text / xml; charset = UTF-8");

I get: OPTIONS / WSoap / Service? WSDL HTTP / 1.1, in the Request and HTTP / 1.1 200 OK in the Response

I hope you can help me

    
asked by E.Flores 16.05.2018 в 17:45
source

0 answers