![](/img/trans.png)
[英]Axios error Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream
[英]Type Error “string” must be a string, Buffer, or ArrayBuffer
我在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);
};
您只需要使用JSON.stringify()
包装您的对象。
所以你的xhr.send看起来像:
xhr.send(JSON.stringify({
FirstName: "john",
LastName: "doe",
MerchantSessionID: "817281271",
DateOfBirth: "12,24,1985",
ProductTypeID: "xxxxxxxxx"
}));
PS不要忘记指向地址(现在是代码中的www.example.com
)来纠正端点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.