使用node.js

时间:2016-05-07 04:14:12

标签: node.js rest https

我有一个要求,Post请求将被发送到Node.js,它必须被发送到具有相同请求主体的https rest端点并返回响应。我尝试过使用Http,node-rest-client npms。这些似乎都适用于http post请求,但不适用于https。任何代码帮助都会很棒。

提前致谢。

1 个答案:

答案 0 :(得分:2)

node-rest-client实际上支持每个文档的HTTPS请求。在初始化客户端时,您可能需要指定:443端口或添加connection选项:

var options = {
    // proxy configuration
    proxy: {
        host: "proxy.foo.com", // proxy host
        port: 8080, // proxy port
        user: "ellen", // proxy username if required
        password: "ripley" // proxy pass if required
    },
    // aditional connection options passed to node http.request y https.request methods 
    // (ie: options to connect to IIS with SSL) 
    connection: {
        secureOptions: constants.SSL_OP_NO_TLSv1_2,
        ciphers: 'ECDHE-RSA-AES256-SHA:AES256-SHA:RC4-SHA:RC4:HIGH:!MD5:!aNULL:!EDH:!AESGCM',
        honorCipherOrder: true
    },
    // customize mime types for json or xml connections
    mimetypes: {
        json: ["application/json", "application/json;charset=utf-8"],
        xml: ["application/xml", "application/xml;charset=utf-8"]
    },
    user: "admin", // basic http auth username if required
    password: "123", // basic http auth password if required
    requestConfig: {
        timeout: 1000, //request timeout in milliseconds
        noDelay: true, //Enable/disable the Nagle algorithm
        keepAlive: true, //Enable/disable keep-alive functionalityidle socket.
        keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
    },
    responseConfig: {
        timeout: 1000 //response timeout
    }
};

有关详细信息,请参阅https://github.com/aacerox/node-rest-client