在JavaScript中POST自定义标头

时间:2017-10-18 12:00:39

标签: javascript xmlhttprequest http-headers

我正在开发一个使用JavaScript中的XmlHttpRequest发送SOAP请求的项目。

我想在我的请求中创建自定义标头,如下所示:

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)

现在,我使用的方法是: xmlHttp.setRequestHeader(" PASSWORD"," toto1"); 结果是这一个(POST请求也被修改为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)

我的问题是:如何将自定义标题设为密码:" toto1" 而不是:访问控制请求标题:密码

如何保留替换为OPTIONS方法的POST方法?

谢谢

0 个答案:

没有答案