如何使用代理集调用Watson API



我正在尝试调用某些API,目前我的服务器要求防火墙请求,我需要设置代理以通过无法为我释放防火墙。

摘要:如何将此API调用我的服务器中的代理服务器设置我的代理服务器,以使用代理?

我尝试使用express-http-proxy和http-proxy,然后尝试:

require('dotenv').config({silent: true});
var httpProxy = require('http-proxy');
var server = require('./app', httpProxy.createServer(function (req, res, proxy) {
  var buffer = httpProxy.buffer(req);
  proxy.proxyRequest(req, res, {
    host: 'pxdproxy.com',
    port: 8080,
    buffer: buffer
  });
});

var port = process.env.PORT || process.env.VCAP_APP_PORT || 443;
server.listen(port, function() {
  // eslint-disable-next-line
  console.log('Server running on port: %d', port);
});

和我呼吁API:

var conversation = watson.conversation({
    url: 'https://gateway.watsonplatform.net/conversation/api',
    username: 'xxxxxxxxxxxxxxxxxxxxx',
    password: 'xxxxxxxxxxxxxxxxxxxxxxx',
    version_date: '2017-12-03',
    version: 'v1',  
});

我需要用代理集调用对话API。

您用来调用node.js调用watson api的SDK使用request库。

为了使用代理来调用服务,您只需要定义一个称为HTTPS_PROXY的环境变量。

根据您的示例,您将使用:

HTTPS_PROXY=pxdproxy.com:8080

更多信息。

最新更新