如何使用Header和Body将cURL片段表示为完整的HTTP请求

时间:2014-01-09 16:50:36

标签: javascript http curl

我阅读并重新阅读下面的堆栈问题的答案,我仍然没有得到它。

有人可以帮我弄清楚(呃,举个例子),如何将一个有效的cURL片段表示为完整的HTTP请求?

Stack question

AND:这是cURL代码段。

curl -s --insecure https://api.yahoo.com/nvp -d“USER=joe@mymail.com& PWD = XXXXXXXXXXXXX& SIGNATURE = YYYYYYYYYYYYYYYYYYYYYYYY& METHOD = SendNow& VERSION = 103& RECEIVERTYPE = EmailAddress& YOURCODE = ABC& EMAILSUBJECT =你有一封新电子邮件& L_EMAIL0=sam@hismail.com& L_SMT0 = 103& L_NOTE0 =爆炸。& L_UNIQUEID0 = TrackNum0001“

我需要表达为:

Parse.Cloud.httpRequest({
method: 'POST',
url: 'http://www.example.com/create_post',
body: {
  title: 'Vote for Pedro',
  body: 'If you vote for Pedro, your wildest dreams will come true'
},
success: function(httpResponse) {
  console.log(httpResponse.text);
},
error: function(httpResponse) {
  console.error('Request failed with response code ' + httpResponse.status);
}
});

1 个答案:

答案 0 :(得分:1)

试试这个:

Parse.Cloud.httpRequest({
    method: 'POST',
    url: 'https://api.yahoo.com/nvp',
    body: {
        USER: 'joe@mymail.com',
        PWD: 'XXXXXXXXXXXXX',
        SIGNATURE: 'YYYYYYYYYYYYYYYYYYYYYYYY' // etcc..
    },
    success: function (httpResponse) {
        console.log(httpResponse.text);
    },
    error: function (httpResponse) {
        console.error('Request failed with response code ' + httpResponse.status);
    }
});