Consume WS with javascript

Asked

Viewed 457 times

0

I’m using Soapui to take the test at WS: Raw do XML

Another image that shows authentication to consume XML: Visão usando soapUi

Only when I try to consume the same xml only through javascript, I can’t (I think it lacks technical knowledge)

$(document).ready(function (){
    var url = 'http://SERVIDOR:PORTA/wsConsultaSQL/IwsConsultaSQL';
    var method = 'POST';
    var postData =
      '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tot="http://www.totvs.com/">\n'
      + '    <soapenv:Header/>\n'
      + '  <soapenv:Body>\n'
      + '  <tot:RealizarConsultaSQL>\n'
      + '  <tot:codSentenca>06</tot:codSentenca>\n'
      + '  <tot:codColigada>1</tot:codColigada>\n'
      + '  <tot:codSistema>S</tot:codSistema>\n'
      + '  <tot:parameters>NUMEROINSCRICAO=192;IDPS=6</tot:parameters>\n'
      + '  </tot:RealizarConsultaSQL>\n'
      + '  </soapenv:Body>\n'
      + '  </soapenv:Envelope>\n';
    var req = new XMLHttpRequest();
    req.open("POST", url, true);
    req.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
    req.setRequestHeader('SOAPAction', '');
    req.withCredentials = true;
    req.setRequestHeader("Authorization", "Basic " + btoa('milrak.pessoa' + ":" + 'MINHASENHA'))
    req.onreadystatechange = function () {
      if (req.readyState != 4) return;
      if (req.status != 200 && req.status != 304) {
        console.log('HTTP error ' + req.status);
        return;
      }
      console.log(req.responseText);
    }
    if (req.readyState == 4) return;
    req.send(postData);
  });

The Error returned is: Erro retornado do código

Someone has done this with javascript or jquery?

  • The header SOAPAction should be empty?

  • @Andersoncarloswoss I’ve been reading some things, will it be because of the security policies, that I can not make or receive request from the same server. (using javascript)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.