代码之家  ›  专栏  ›  技术社区  ›  user08152017

HTTPS Get在使用nodejs连接Bing API时出现连接被拒绝错误

  •  0
  • user08152017  · 技术社区  · 7 年前


    Error: connect ECONNREFUSED 127.0.0.1:443
    at Object.exports._errnoException (util.js:1018:11)
    at exports._exceptionWithHostPort (util.js:1041:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    
    Code:
    
    exports.handler = (event, context, callback) => {
    var headers = {
    'Ocp-Apim-Subscription-Key': '******************',
    'Content-Type': 'application/json',
    };
    var options = {
    url: 'https://api.cognitive.microsoft.com/bing/v5.0/search?                
    &q=hello',
    method: 'GET',
    headers: headers,
    };
    const https = require("https");
    https.get(options);
    };
    

    谢谢你的帮助

    1 回复  |  直到 7 年前
        1
  •  0
  •   Manoj    7 年前

    您可能需要并使用该软件包 node-bing-api 使用Bing Api进行搜索。

    var Bing = require('node-bing-api')({ accKey: "your-account-key" });
    
    Bing.web("hello", function(error, res, body){
       console.log(body);
     });