从节点调用 Url 不起作用节点、不起作用、Url

由网友(梦一场)分享简介:我使用邮递员调用带有标头等的 URL,这工作正常(我能够在邮递员调用中获取令牌),当我尝试从节点使用它时它不起作用,我收到以下错误:I use postman to call to URL with headers etc which is working fine ( I was able to get the t...

我使用邮递员调用带有标头等的 URL,这工作正常(我能够在邮递员调用中获取令牌),当我尝试从节点使用它时它不起作用,我收到以下错误:

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

我什至从邮递员复制代码并在一些简单的 node.js 应用程序中使用它,但它无法正常工作,知道这里可能有什么问题吗?

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);
    });
})

推荐答案

如果您使用的是公司代理,请按如下方式设置 NPM 代理设置.

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 
阅读全文

相关推荐

最新文章