Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用代理集调用Watson API_Node.js_Proxy_Ibm Watson - Fatal编程技术网

Node.js 如何使用代理集调用Watson API

Node.js 如何使用代理集调用Watson API,node.js,proxy,ibm-watson,Node.js,Proxy,Ibm Watson,我正在尝试调用一些API,目前我的服务器请求防火墙,我需要设置代理以通过,因为with proxy工作正常,出于安全原因,公司无法为我释放防火墙 摘要:如何调用此API设置我的代理服务器,并将服务器中的代码用于所有使用代理的请求 我尝试使用express http proxy和http proxy,并尝试: require('dotenv').config({silent: true}); var httpProxy = require('http-proxy'); var server =

我正在尝试调用一些API,目前我的服务器请求防火墙,我需要设置代理以通过,因为with proxy工作正常,出于安全原因,公司无法为我释放防火墙

摘要:如何调用此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使用该库

为了使用代理调用服务,您只需要定义一个名为
HTTPS\u proxy
的环境变量

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

HTTPS_PROXY=pxdproxy.com:8080
更多信息