如何通过Node.JS上的请求模块(POST方法)传递数据?

时间:2018-07-25 14:19:51

标签: javascript node.js api request mocha

我正在执行以下步骤,但出现错误。我认为它没有通过身体。但是,get方法在此步骤中工作正常。

var request = require("request");
var should = require("should");
var expect = require("chai").expect;
var baseUrl = "https://na73.salesforce.com/services";
const config  = require("../../../lib/config");
const url  = require("../../data/url");

describe('Get Call Record Resource list', function() {
    this.timeout(config.timeOut);
    it('Verify in Dialer Config api, able to get Dialer Config list', function(done) {
        request.post({
                headers: {
                    Authorization: `Bearer ${config.token}`
                },
            body:{
                "callId": {
                    "callConnectService": "RING_CENTRAL",
                    "serviceCallId": "1564283263244352",
                    "externalId": "1564283263244352"
                },
                "appointmentId": "a181I000001IMOlQAO",
                "entityId": "0031I00000MxBw8QAF",
                "phoneNumberCalled": "+13175221101"
            },
                url: baseUrl +  `${url.CallRecordResource}`
            },
            function(error, response, body) {
                var bodyObj = JSON.parse(body);
                expect(response.statusCode).to.equal(200);
                expect(response.body).should.exists;
                should.not.exist(error);
                expect(response.body).to.not.be.undefined;
                done();
            });
    });
});

0 个答案:

没有答案