我想通过 JavaScript 将 POST 请求发送到具有一些请求标头和帖子正文的不同主机。
我怎样才能做到这一点?
我用 XMLHttpRequest 尝试过,但出现以下错误:
0x80004005 (NS_ERROR_FAILURE)
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", "https://somedomain/deviceapi/v1/rest/registration/device/anonymous", false);
xmlHttpRequest.setRequestHeader("Accept", "application/json");
xmlHttpRequest.setRequestHeader("some key", "some value");
xmlHttpRequest.setRequestHeader("Accept-Charset", "UTF-8");
xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlHttpRequest.send("some data");