【发布时间】:2018-04-24 19:16:54
【问题描述】:
我在 Node 中尝试向端点发送 http 调用。我没有得到任何回应,而且我确定我的设置不正确。我的请求适用于邮递员。任何帮助都会很棒!
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
curlUpdate = function curlUpdate() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "www.example.com", false);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send({
FirstName: "john",
LastName: "doe",
MerchantSessionID: "817281271",
DateOfBirth: "12,24,1985",
ProductTypeID: "xxxxxxxxx"
});
console.log(xhr.responseText);
};
【问题讨论】:
-
我认为您应该将字符串传递给
send而不是对象。在将对象传递给send之前尝试JSON.stringify。 -
是的,这似乎可行,谢谢! @ibrahimmahrir
标签: javascript node.js xmlhttprequest