我在查看 Node js 应用程序和 API 之间交换的信息时遇到困难。
开发人员正在使用请求模块。查看自述文件,有一个名为"代理"的选项:
proxy - An HTTP proxy to be used. Supports proxy Auth with Basic Auth, identical to support for the url parameter (by embedding the auth info in the uri)
但是,当我添加代理作为选项时,它似乎被丢弃了,因为当请求传递到服务器时,我在我的 http 代理(查尔斯或小提琴手)中看不到任何信息
我正在使用的选项是:
exports.defaultOptions = function(){
return {
host: config.apiHost, // API url to connect too
headers: { 'Content-Type': 'application/json' },
method: 'POST', // Default method
port: config.apiPort, // API port number to connect too
proxy: 'http://192.168.2.183:8888'
};
};
我尝试了其他调试流量的方法(隧道代理、代理链),但这些似乎都会导致 CONNECT 方法而不是 GET 或 POST。
如果有人有任何使用代理选项的经验,或者如果我从根本上误解了代理选项的实现或使用,请告诉我。
谢谢
使用"url"而不是"host"。 我假设从内联注释中,它是 API 端点的完整 URL。
exports.defaultOptions = function(){
return {
url: config.apiHost, // API url to connect too
headers: { 'Content-Type': 'application/json' },
method: 'POST', // Default method
port: config.apiPort, // API port number to connect too
proxy: 'http://192.168.2.183:8888'
};
};
从文档 :乌里 ||URL - 完全限定的 URI 或来自