Pass Web Service header parameters?

Asked

Viewed 444 times

0

I am trying to perform a web service call on Angularjs, however I am getting the following error message on the browser console (tested on Chrome and Firefox):

Xmlhttprequest cannot load

No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:8083' is therefore not allowed access.

From what I understand soap complained I didn’t send the order headers. Actually the service requires headers as below, however I do not know how to pass them in the call parameter post, I just sent the parameters of body of the requisition.

Header parameters: user and store:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

   <soapenv:Header>
      <v1:header>
         <usuario>?</usuario>
         <loja>?</loja>
      </v1:header>
   </soapenv:Header>
   <soapenv:Body>
      <v1:inImprimirFatura>
         <tipo-fatura>?</tipo-fatura>
         <numero-cpf>?</numero-cpf>
      </v1:inImprimirFatura>
   </soapenv:Body>
</soapenv:Envelope>

Service that makes the post call:

function GerarSegundaViaFaturaTotvsPDF()
{
	var metodo = 'imprimirFatura';
	var url = '
	var param = {};      	 
	param.tipoFatura = "ATUAL";
	param.CPF =
	return $soap.post(url, metodo, {req: param});	      	 
}

How do I pass the header parameters in the call simply without changing the structure of my code?

1 answer

0


Usually this type of error is related to CORS (Cross-Origin Resource Sharing).

In this post https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource you can check better and have two more references explaining the concept. One of them I cloned above. Below follows the quote from the post that I believe has to do with your problem:

If I understood it right you are Doing an Xmlhttprequest to a Different Domain than your page is on. So the browser is blocking it as it usually Allows a request in the same origin for security reasons. You need to do Something Different when you want to do a cross-Domain request. A tutorial about how to Achieve that is Using CORS.

Browser other questions tagged

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