使用原始数据发布请求,在mocha上抛出400个错误请求

时间:2018-02-02 10:24:49

标签: javascript json

var expect=require('chai').expect;
var http=require("http");
var request = require('request');
var env = require('./environment');

describe("Callflow TestCase", function(done) {
  //this.timeout(15000);
  it("minutes field ",function(done){
    var formData = [{
        "variables":[{"name": "OpMode",
        "value":"3",
        "section": "Treatment",
        "type": "queue"}]
    }]
    var data=(JSON.stringify(formData));
    console.log(data);

    console.log(JSON.stringify(formData));
    var options={
      url:env.hostname+'variables/menus/Call%20Flow?siteName=VHT%20TITAN&queueId=VHT_Test&segmentId=6&segmentName=58897&allQueues=false&allSegments=false',
      **raw:data**,
      headers:{
        //'lastAccess':1516781803697,
        'Token':'14275bb3c2fbc60d0dac05113dac1d6bcf3ccde00cf2699c43efedd820c2660a',
        //'ttl':2592000000,
        'Content-Type': 'application/json'
      }
    }
    request.post(options,function(err,res,body) {
      //console.log(JSON.stringify(options.raw));
      console.log(options);
      //body=JSON.parse(body);
      expect(res.statusCode).to.equal(204);
      done();
   });
  });
});

注意:如果我给表单,在原始位置,它会抛出500内部服务器错误。 Same Object在邮递员上工作正常。如果iam在邮递员中测试此案例,我将获得204无内容。

1 个答案:

答案 0 :(得分:0)

尝试

var options = {
    ...
    form: data,
    ...
}

来自doc