POST请求内的标头值设置为null nodejs

时间:2018-01-08 00:30:17

标签: node.js http-headers nock

我一直在尝试使用nock从我的test.js执行POST请求到Node.js。我不明白,虽然我传递了标题值,但节点上的request.payload(body)值为null,因为标题值在到达服务器时变为null。

  scope = nock('http://localhost:3000')
        .post('/Channel/register', payload,headers)
        .reply(200, {status: 200});

});
request.post('http://localhost:3000/Channel/register', function(err, body) {
    console.log(err, null);
});

    request.post({url:'http://localhost:3000/Channel/register',
                headers: JSON.stringify({
                    "content-type" : "application/x-www-form-urlencoded",
                    'warning': "with content type charset encoding will be added by default",
                    "content-length": 50
                }),
                mode: 'no-cors',
                body: JSON.stringify({
                     Channel: "Cricket",
                     codes: "c--HOjyWVww:APA"
                })
            },  function (err,response) {
                // console.log(request);
                console.log("+response status code:", response.statusCode);
                console.log(response.failureCount);
                if (err) {
                    throw err; // => Error: Nock: No match for request POST http://foobar.com/ {"foo":"biz"}
                }
                done();
            });


});

0 个答案:

没有答案