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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With