How to get the server ip address that the httpClient connected to and exchanged the request/response

Not applicable

Hi all,

I'm using a Javascript based HTTP callout to a backend server say test.com, how can i know the actual server IP address to which the request was sent? is there a field on ex1 or httpClient or some such variable or field that Apigee will fill in?

var req = new Request("https://test.com/api", 'POST', headers, requestBodyStr);

var ex1 = httpClient.send(req);

Please suggest a way to get the server ip address to which the httpclient connected to.

thanks

Mallesh

0 3 5,379
3 REPLIES 3

I don't know of a way. What are you REALLY trying to do?

Not applicable

We are using Javascript policy to orchestrate with multiple backend servers. We log all messages sent to and responses received from each backend server. The target ip address is one such information that we capture. Since the backend server is not the Target Endpoint of the API Proxy therefore the "target.ip" context variable is not going to be updated with each of the backend servers contacted in the Javascript. Thus wanted to know if there is a mechanism that can be used to know exact backend server that was used for connecting.

I don't know of a way to do what you want with the JS policy and the embedded httpClient.

There's no property that allows that.

You can do what you want from within nodejs app. If you use the http/https module:

  var http = require('https');
  http.get('https://www.google.com', function(res) {
    console.log('remote IP: ' + res.connection.remoteAddress);
    ...
  });

If you use request:

var request = require('request');

    var options = {
          url : 'https://www.google.com',
          method : 'get'
        };
    request(options, function(e, response, body) {
        if (e) {
          console.log('Error ' + e);
        }
        ...
      })
      .on('socket', (socket) => {
        socket.on('connect', function(){
          console.log('remote IP: ' + socket.remoteAddress);
        });
      });