Node.js 第三方包Request

發送POST請求,提交數據:

var request = require('request');

(1)提交JSON數據:

var jSONObject = { ... };
request({
    url: url,
    method: "POST",
    json: true, 
    body: jSONObject
}, function (error, response, body){
    console.log(response);
});

(2) 提交XML數據:

var xMLText = '<xml>...........</xml>';
request({
    url: url,
    method: "POST",
    headers: {
        "content-type": "application/xml", 
    },
    body: xMLText
}, function (error, response, body){
    console.log(response);
});


發佈了45 篇原創文章 · 獲贊 14 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章