Jarred Allen
Jarred Allen

Reputation: 362

How do I verify that my Java code actually sent a POST request?

In my java code, I need to send a POST request to a server that is run by someone else in order to login on their server. However, my attempt to log in is not working.

I would like to be able to pinpoit which part of my code is producing this error. Is there a way I can check to see if the error lies in the POST request not being sent, making the connection a GET request?

Upvotes: 0

Views: 762

Answers (2)

Gowtham
Gowtham

Reputation: 652

If you are using HttpClient library to send HTTP POST requests then I would suggest modify your log4j.properties file as follows

#Logger configuration for Apache Commons HTTP Client
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
log4j.logger.httpclient.wire=debug, stdout

This would print the complete request (Headers, Body, URL & params) & response (Headers, Body) that is going on the wire.

Hope that helps

Upvotes: 1

nicholasnet
nicholasnet

Reputation: 2287

You can see your request in developer toolbar that is available in browser. If that is not an option for you then you can use tools like Charles Debugger or Wireshark.

Upvotes: 1

Related Questions