0

I am working on a project to send an SOAP request using XmlHttpRequest in JavaScript.

I want to create custom headers in my request like this:

POST https://www.toto.com/soap HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Password: "toto1"
Content-Length: 621
Host: www.toto.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Now, I am using the method : xmlHttp.setRequestHeader("PASSWORD", "toto1"); And the result is this one (The POST request is also modified to OPTIONS):

Request Method:OPTIONS
Accept:*/*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8,fr;q=0.6,en-GB;q=0.4,es;q=0.2,en-NZ;q=0.2
Access-Control-Request-Headers: password
Access-Control-Request-Method:POST
Content-Length: 621
Host: www.toto.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

My question is: how to have the custom header as Password: "toto1" and not as: Access-Control-Request-Headers: password

And how can I keep the POST method which is replace with a OPTIONS method ?

Thanks

Louise Godec
  • 221
  • 1
  • 2
  • 11
  • That's normal behaviour. The request isn't being changed, that is just the [preflight request](https://developer.mozilla.org/en-US/docs/Glossary/preflight_request) being made before the actual POST. Do you not see the POST request after this OPTIONS request? If not, check the response from the preflight. You may need to configure your server to handle OPTIONS requests, or change your setup to avoid cross-origin requests. – Karl Reid Oct 18 '17 at 12:04
  • I have no mean to change the SOAP service (because it is develop by an other society ). Is there a mean to avoid cross-origin request from my client app? – Louise Godec Oct 18 '17 at 12:15
  • If the server is responding with a 500 when you make an OPTIONS request, it is badly configured so you need to talk to whoever can fix that. To avoid cross-origin requests, you need to set up your project so that your web app is hosted on the toto.com domain as well. – Karl Reid Oct 18 '17 at 12:23
  • Ok, thanks for all this tips ! – Louise Godec Oct 18 '17 at 12:48

0 Answers0