Пытаюсь отправить POST-запрос на веб-сервер. А вместо этого от отправляется OPTIONS.
Заголовок запроса:
OPTIONS / HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Origin: null
Connection: keep-alive
Cache-Control: max-age=0
заголовок ответа:
HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Allow: HEAD, GET, OPTIONS, POST
Content-Length: 0
Server: Werkzeug/0.11.10 Python/3.5.1
Date: Sun, 21 Aug 2016 07:51:35 GMT
Сам код:
var idClient, emailClient, ipClient, dateClient, urlClient, fileHashClient;
idClient = Date.now();
urlClient = window.location.href;
dateClient = Date.now();
var xhr = new XMLHttpRequest();
var json = JSON.stringify({
id: idClient,
email: emailClient,
ip: ipClient,
date: dateClient,
url: urlClient,
fileHashClient: fileHashClient
});
alert(json);
xhr.open("POST", "http://127.0.0.1:5000/", true)
xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8');
//http.setRequestHeader("Content-length", json.length);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
}
xhr.send(json);
Где я ошибся?