我正在尝试使用以下
通过https发送休假请求// Construct the POST auth body and options
let postData = JSON.stringify({
username: this.state.username,
password: this.state.password
});
console.log(postData);
var options = {
host: this.state.peerAddress,
port: this.state.port,
path: "/api/" + this.state.channelName + "/user-authorisation",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": postData.length
}
};
console.log(options);
var postRequest = https.request(options, function(res) {
console.log("\nstatus code: ", res.statusCode);
res.setEncoding("utf8");
res.on("data", function(data) {
console.log(JSON.parse(data));
});
});
e.preventDefault();
// post the data
postRequest.write(postData);
postRequest.end();
该请求已发送到服务器,但没有正文。我已经通过邮递员发送相同的请求进行了测试,并且效果很好。我会在Chrome上发送请求吗?我在控制台上收到以下错误,但我认为这些错误是在发送请求后发生的,因此,这在当时并不是真正的问题。
request.js:149 OPTIONS https://<<address>>:<<port>><<path>> net::ERR_CONNECTION_REFUSED
localhost/:1 Uncaught (in promise) TypeError: Failed to fetch
任何帮助将不胜感激! 干杯