Reputation: 855
I have a requirement, a Post request will be sent to Node.js and it has to be sent to a https rest endpoint with the same request body and return the response. I have tried using Http, node-rest-client npms. Those all seem to work for a http post request but not with https. Any help with code will be great.
Thanks in advance.
Upvotes: 0
Views: 1329
Reputation: 1419
node-rest-client
actually supports HTTPS requests per the documentation. You may need to specify a :443 port or add the connection
option when initializing the client:
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
}
};
See https://github.com/aacerox/node-rest-client for details.
Upvotes: 2