Call to Url from node is not working

2019-05-31 17:31发布

I use postman to call to URL with headers etc which is working fine ( I was able to get the token in postman call ) and when I try to use it from node its not working , i Got the following error :

Error: Error: connect ECONNREFUSED 35.122.111.52:445

I even copy the code from postman and use it in some simple node.js app and its not working , any idea what could be wrong here ?

const server = app.listen(port, () => {
    "use strict";
    console.log("Server listen to port :" + port);

    var options = {
        method: 'POST',
        url: 'https://app.authentication.orc.com/oauth/token',
        headers: {
            grant_type: 'client_credentials',
            authorization: 'Basic c2ItY2xvbmUzZjkwNWRmNmRkYzg0YmXCRjlkZmQ0MDdmMCFiMTc0fGNvbm5lY3Rpdml0eSFiMTM3OkpYQUlyd1BrS2tlQVRDWThDNDFsdkhibGNTbz0=',
            accept: 'application/json;charset=utf-8',
            'content-type': 'application/x-www-form-urlencoded'
        },
        form: {
            grant_type: 'client_credentials',
            token_format: 'opaque&response_type=token'
        }
    };

    request(options, function (error, response, body) {
        if (error) throw new Error(error);

        console.log(body);
    });
})

1条回答
爷、活的狠高调
2楼-- · 2019-05-31 18:05

If you are behind a corporate proxy then set NPM proxy settings as below.

npm config set proxy http://"user:P@ssword"@proxy.server:8080 
查看更多
登录 后发表回答