我从CURL转换的NodeJS请求有什么问题?

时间:2015-09-06 04:01:41

标签: node.js curl

我有一个CURL请求,可以提供我需要的结果:

curl "http://www.domain.com/verification/" --data "ID=123456789&DL=123456789&submit=submit"

然而,当我把它变成这样的NodeJS请求时:

var request = require('request');

var dataString = 'ID=123456789&DL=123456789&submit=submit';

var options = {
    url: 'http://www.domain.com/verification/',
    method: 'POST',
    data: dataString
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);

它给了我一个不同的回答......这有什么问题?

2 个答案:

答案 0 :(得分:1)

像这样使用:

request.post({
   url:'http://www.domain.com/verification/', 
   form: {
    ID: '123456789',
    DL: '123456789',
    submit: 'submit'
   }
  },
 function(error,response,body){ 
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
 });

答案 1 :(得分:-2)

试试这个 -

var request = require('request');
var options = {
    url: 'http://www.domain.com/verification/',
    method: 'POST',
    form: { "ID":"123456789","DL":"123456789","submit":"submit"}
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);