带有表单数据和查询字符串的nodejs中的Http请求

时间:2016-02-01 15:27:42

标签: node.js httprequest

如何在nodejs中发送查询字符串参数和表单数据参数。我尝试了以下代码。但它不起作用。它只是悬挂而没有响应。

var url_req = require("request");
    url_req({
        pool: separateReqPool,
        url: "https://somthing.com/v1/message/userF",
        method: 'POST',
        qs: {
            action: "send-message",
            c: "somecode_c",
            cache: new Date().getTime(),
            sid: "somecode_sid"
        },
        form: {
            convId: "userF~userT~esp",
            message: "<font face='Arial' size='10'>.</font>",
            sendAs: "userF",
            txnId: "userF~" + new Date().getTime() + "~number",
        },
        headers: {
            'Content-Type': 'application/json;charset=utf-8',
            'Cookie': 'some cookies',
            'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0',
            'Accept-Language': "en-US,en;q=0.5",
            'Connection': "keep-alive",
            'Pragma': "no-cache",
            'Cache-Control': "no-cache",
            'Referer': "https://something.com/xframe.html?bc",
            'Accept': ' text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Content-Length': 100,
            'Host': "something.com"
        }
    }, function (error, response, body) {
        if (error)
            console.log(error);
        else
            console.log(body);
    });

0 个答案:

没有答案