感谢您的上述评论,这些评论有助于我理解问题。为了解决这个错误,我没有直接从客户端发布请求,而是将请求发送到服务器端,然后从服务器端调用请求,这完全消除了CORS问题,并提供了对数据的更多控制。
从客户的角度来看,我做到了
$.ajax({
url: /post/request-to,
type: "POST",
data: JSON.stringify(queryData),
contentType: "application/json"
}).done(function(message){
event.preventDefault();
console.log(message);
return;
});
然后在服务器脚本中
app.post('/post/request-to', function(req, res){
try{
request.post({
headers: {'content-type' : 'application/json'},
url: "http://some/url",
body: JSON.stringify(req.body)
}, function(error, response, body){
if(error){
console.log("Error: "+error)
}else{
res.send(body)
}
});
console.log(req.body);
}catch(err){
console.log(err)
}
});