Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get full HTTP request

For debugging matters, I would like to get the request executed by Unirest-Java when presented with a set of options. How can I get this:

POST / HTTP/1.1
Host: www.some.host.tld
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
field1=FIELD1&field2=FIELD2

From this:

HttpRequest request = Unirest.post(SOMEHOST_URL)
            .field("field1" , FIELD1)
            .field("field2", FIELD2)
            .getHttpRequest();

That is, how can I get the full HTTP request from a HttpRequest? I don't really know of a proxy to use, as the only one with which I could get SSL support working was Charles, and for some reason it won't pickup the java traffic. Other tools would choke on the SSL mainly because the server I need to talk to is flawed, using self-signed certificates and invalid hostnames. So I would gladly try a proxy, but it has to work under these conditions. Better would be to extract this information from Unirest/HTTPClient itself. I already tried building the HttpClient with .setInterceptorFirst( but I couldn't get the request body from the interceptor, only some of its headers.

like image 646
Délisson Junio Avatar asked Sep 21 '14 20:09

Délisson Junio


People also ask

How do I get HTTP request?

HTTP GET Request FormatThe GET request consists of the request-line and HTTP headers section. The GET request-line begins with an HTTP method token, followed by the request URI and the protocol version, ending with CRLF. Space characters separate the elements.

What is the function of get in HTTP requests?

GET method is used to retrieve information from the given server using a given URI. The GET method sends the encoded user information appended to the page request.

What is full request URI?

5.1. The Request-URI is a Uniform Resource Identifier (section 3.2) and identifies the resource upon which to apply the request. Request-URI = "*" | absoluteURI | abs_path | authority. The four options for Request-URI are dependent on the nature of the request.


1 Answers

I have never used Unirest, but it uses Apache HTTP client 4, so setting debug level logger on org.apache.http should give you all the data transferred including headers and content.

Please see how to do it depending on the log system you use at

Edit: https://hc.apache.org/httpcomponents-client-4.5.x/logging.html

like image 194
volkovs Avatar answered Sep 25 '22 14:09

volkovs