Four Stars

tRestRequest HTTP headers (IP address/ hostname/ client details)

Hello!

I want to capture source request information (IP address/ hostname/ client details)[HTTP headers ] when I use tRestRequest.

Please help, how I can do it?

7 REPLIES
Moderator

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

Hello,

You can access individual headers by adding parameters in a schema editor and adding a 'header' to the Comment field. tRESTRequest also sets the map of all the headers it receives as a context var which means All HTTP headers are available as a map on the request context.

Bestr regards

Sabrina

--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Four Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

I added 'header' in a schema editor to the Comment field:

 

image.png

image.pngimage.pngimage.png

Eight Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

Hi,

 

In field column, you have to set the name of your header value.

 

Eric

Four Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

Field column does not accept dash, for example: how I can get X-Forwarded-For?

Eight Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

Hi,

 

With this piece of code in a tJavaFlex, you can get your header value (In my example, header name is NAME-TEST):

java.util.Map<String, java.util.Map<String, List<String>>> restReq =
(java.util.Map<String, java.util.Map<String, List<String>>>)globalMap.get("restRequest");
java.util.Map<String, List<String>> headers = restReq.get("ALL_HEADER_PARAMS");
List<String> myheader = headers.get("NAME-TEST");
String headervalue = myheader.get(0);
System.out.println(headervalue);

 

Eric

Four Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

Thx, I know this method, but I think it is not true way. It is stop gap solutions)

Seven Stars

Re: tRestRequest HTTP headers (IP address/ hostname/ client details)

yeah, there is no "native" support for capturing these fields. Even I am currently using the stop-gap alternative.