【发布时间】:2016-10-18 15:27:17
【问题描述】:
所以我正在尝试使用request 模块将新用户发布到对讲机,但似乎无法正确获取格式。我可以用请求和 POST 用 CURL 的相同数据来做 GET 请求。所以我的结论是我使用请求库的方式一定有问题。
工作 CURL 请求:
curl https://api.intercom.io/users \
-X POST \
-u xxx:da39xxxxxxxxxxxxxxxxx0709 \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' -d '
{
"user_id": "25",
"email": "wash@serenity.io",
"name": "Hoban Washburne",
"signed_up_at": 1392731331,
"last_seen_ip" : "1.2.3.4"
}
服务器端请求无效:
request.post('https://api.intercom.io/users',
{
'auth': {
'user': 'xxx',
'pass': 'xxx',
'sendImmediately': false
}},
{
"user_id": "193",
"email": "test@test.io",
"name": "Hoban Washburne",
"signed_up_at": 1392731331,
"last_seen_ip" : "1.2.3.4",
},function (error, response, body) {
var info = JSON.parse(body);
console.log(info);
console.log(error);
});
res.status(200).send(info);
【问题讨论】:
-
有什么问题?
-
您...可能想要撤销该 API 密钥...
-
这只是文档中的示例 API 密钥。 @slugonamission
标签: node.js express npm http-post httprequest