我正在尝试从 NodeJS 应用程序向粒子云发送请求。我正在使用 Axios 发出 PUT 请求。应用程序通过同样配置的代理服务器发送请求。
// axios proxy - not working
axios.default.put("https://api.particle.io/v1/devices/<deviceId>/ping", {}, {
proxy: {host: <proxy_ip>, protocol:'http', port:<port_no>},
headers: {
authorization: "Bearer <access_token>"
}
}).then((response) => {
console.log("Success", response.data);
}).catch((error) => {
console.log("Failed", error);
});
Run Code Online (Sandbox Code Playgroud)
错误消息:请求失败,状态代码 400
当我发送此请求时,我收到来自粒子云的 400 Bad Request 响应。但是当我使用NodeJS的请求模块发送相同的请求时,请求成功。
var options = {
method: 'PUT',
url: 'https://api.particle.io/v1/devices/<device_id>/ping',
proxy: {hostname: <proxy_ip>, protocol:'http', port:<port_no>},
headers:
{
authorization: 'Bearer <access_token>'
},
form: false
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response);
}); …
Run Code Online (Sandbox Code Playgroud)