创建 Node CLI 以从 CL 创建存储库,在发布到 github api 时遇到问题。我正在使用请求模块发布到 github API。
request.post({
url: 'https://api.github.com/user/repos',
headers:{
'User-Agent': 'git CL - node',
'Content-type': 'application/json'
},
auth:{
username: '-username-',
password: '-password-'
},
form:{
name: "a-new-repo"
}
}, function(err, res, body){
console.log(body);
});
我收到的错误是{"message":"解析 JSON 时出现问题","documentation_url":"http://developer.github.com/v3"}
我尝试了很多东西,比如
- 设置多部分数据
- 正文而不是表单数据
- 设置内容类型
- 以 JSON 形式发送
我所知道的都是正确的
- 身份验证 --- 如果我执行 GET 请求,我就能得到正确的响应,它只是 POST
- POST 路径和 header
最佳答案
将json
设置为您要发送的数据,而不是form
:
request.post({
url: 'https://api.github.com/user/repos',
headers:{
'User-Agent': 'git CL - node',
'Content-type': 'application/json'
},
auth:{
username: '-username-',
password: '-password-'
},
json:{
name: "a-new-repo"
},
}, function(err, res, body){
console.log(body);
});
关于javascript - 使用 Node 从 CL 创建存储库时出现 Github API 错误,JSON 解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21500786/