views:

44

answers:

3

Hey guys, I want to make some API calls to a server and Im using HttpURLConnection to do so. But the request are not successfull but return

<error>
  <http_status>400 Bad Request</http_status>
  <message>Unexpected request Content-Type header ''. Expecting 'application/x-www-form-urlencoded'.</message>
</error>

So I want to check what the "real" content is, that is send to the server. By real content I mean the exact HTTP Request.

Any ideas how I can see this?

// edit based on the first answers here I should clarify my problem: I want to avoid using an external program like HTTP sniffer or anything and I was hoping that there is a function or a property or whatever that holds the information I am looking for.

If that is not the case, does someone know if this information can be manually rebuild (for example by callin several functions like getRequestMethod() etc...)

I am facing this problem kinda often so that - for me - its worth the effort to build such a functionality myself. Just need to know how :)

Regards

A: 

Use something like tcpdump, which can dump the actual network packets that are emitted or received by your computer.

Tassos Bassoukos
A: 

tcpdump will work, but it can be hard to make it do what you want. NetCat is more user-friendly (here's the project page: http://netcat.sourceforge.net/ - most Unix platforms already include it).

nc -l 9999

This will listen on TCP port 9999, and when an HTTP client connects, it'll print out the full text of the request.

Mike Baranczak
+1  A: 

You can put the HttpURLConnection in debug mode by enabling java.logging with

-Djava.util.logging.config.file=logging.properties

and put in logging.properties (by default in JRE_HOME\lib) the following property

sun.net.www.protocol.http.HttpURLConnection.level = ALL
RealHowTo
I dont really know what I have to do with the line of code you mentioned above.. where do I need to put this? (using eclipse as IDE)
Hirnhamster