创build从CL与节点,JSONparsing错误的回购时Github API错误

创build一个节点CLI从CL创build回购站,发布到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":"Problems parsing JSON","documentation_url":"http://developer.github.com/v3"}

我已经尝试了很多东西,比如

  • 设置多部分数据
  • 而不是表单数据
  • 设置内容types
  • 作为JSON发送

我知道的事情是正确的

  • 身份validation—我能够得到正确的答复,如果我做一个GET请求,它只是POST
  • POSTpath和标题

链接请求模块

链接为github-api

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); }); 

在API文档中有一个名为json的参数,您是否试过将其设置为true

从我的阅读中,这是将表单数据作为JSON结构发送而不是在请求主体中进行表单编码所必需的。

 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" }, json: true }, function(err, res, body){ console.log(body); });