nodejs 和 Circleci 的奇怪行为 api

Strange behavior with nodejs and Circleci api

我们正在尝试使用 nodejs https 库向 circleci rest api 发出 api 请求并返回似乎格式错误的内容 JSON .不幸的是,这只发生在我们使用节点而不是节点时,例如curl,或邮递员。

这是节点代码

var https = require('https');

https.get("https://circleci.com/api/v1/projects?circle-token=OUR-API-KEY", function(response) {
  var body = "";
  response.on('data', function (chunk) {
    body += chunk;
  });

  response.on('end', function () {
    console.log("TEST", body);
  });
});

这是结果的第一部分

TEST ({:irc_server nil, :scopes (:write-settings :view-builds :read-settings :trigger-builds :all :status :none), :irc_keyword nil,  

这是我们用 curl

做同样事情时的样子
$ curl https://circleci.com/api/v1/projects?circle-token=OUR-API-KEY
[ {
  "irc_server" : null,
  "ssh_keys" : [ ],
  "branches" : {
    "master" : {
      "last_non_success" : {
        "outcome" : "failed",
        "status" : "failed",
        "build_num" : 41,
...

我们还注意到 node 响应中似乎有一些 java 残留。这是节点响应的不同部分的示例

...
"pushed_at" #object[org.joda.time.DateTime 0x2753b900 "2015-11-29T14:22:42.000Z"],
"added_at" #object[org.joda.time.DateTime 0x686553cb "2015-11-30T16:07:28.250Z"]},
...

据我们所知,这不是节点问题,因为当我们将脚本中的地址更改为“https://randomuser.me/api/”时,我们得到

TEST {"results":[{"gender":"female","name":{"title":"mrs","first":"milja","last":"makinen"},"location":{"street":"7070 pispalan valtatie","city":"geta","state":"central finland","postcode":24464},"email":"milja.makinen@example.com","login":{"username":"brownwolf135","password":"triton","salt":"Ahx7UsGp","md5":"aa3abe69ad2001470c00de947d112270","sha1":"cc0db5a4ecd489d6f53876ae143cdab117edbba3","sha256":"488268929cd6da0e50fbb61666ddd03136a3ad16914822a650c5d134db9364af"},"registered":1031987491,"dob":908944207,"phone":"05-992-273","cell":"046-791-11-07","id":{"name":"HETU","value":"60770785-G"},"picture":{"large":"https://randomuser.me/api/portraits/women/73.jpg","medium":"https://randomuser.me/api/portraits/med/women/73.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/women/73.jpg"},"nat":"FI"}],"info":{"seed":"ea5f8a5a02e09d48","results":1,"page":1,"version":"1.0"}}

如您所见,不是括号。我们真的是第一个发现这一点的人,还是我们遗漏了一些非常明显的东西?

您是否尝试提供 Accept-Header (https://circleci.com/docs/api/#accept-header)?

If you specify no accept header, we’ll return human-readable JSON with comments. If you prefer to receive compact JSON with no whitespace or comments, add the "application/json" Accept header