如何使用代理集调用 Watson API

How to call Watson APIs with proxy set

我正在尝试调用一些 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

更多信息here