简体   繁体   中英

Nodejs request 'proxy' option is not routing request through defined host

I am having difficulty viewing the information exchanged between a Node js application and an API.

The developers are using the request module. Looking at the readme there is an option called 'proxy':

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)

However when I add in the proxy as an option it seems to be discarded because while the request is passed to the server I see no information in my http proxy (Charles or Fiddler)

The options I am using are:

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'
  };
};

I have tried other methods of debugging the traffic (tunneling agents, proxychains) but these all seem to result in a CONNECT method rather than a GET or a POST.

If anyone has any experience of using the proxy option, or indeed if I have fundamentally misunderstood the implementation or use of the proxy option, please let me know.

Thanks

Use 'url' instead of 'host'. I'm assuming from the inline comment, it is a full url to the endpoint of the api.

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'
  };
};

From docs : uri || url - fully qualified uri or a parsed url object from

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM