HTTPS request in NodeJS

后端 未结 1 1132
名媛妹妹
名媛妹妹 2021-01-30 15:59

I am trying to write a NodeJS app which will talk to the OpenShift REST API using the request method in the https package. Here is the code:

var https = require(         


        
1条回答
  •  醉梦人生
    2021-01-30 16:31

    Comparing what headers curl and node sent, i found that adding:

    headers: {
        accept: '*/*'
    }
    

    to options fixed it.


    To see which headers curl sends, you can use the -v argument.
    curl -vIX GET https://openshift.redhat.com/broker/rest/api

    In node, just console.log(req._headers) after req.end().


    Quick tip: You can use https.get(), instead of https.request(). It will set method to GET, and calls req.end() for you.

    0 讨论(0)
提交回复
热议问题