0

I was playing around with the HTTP POST and GET requests in Java. I was just trying to mimic the requests that my browser sends using Java (I am using the URLConnection class). However, when I used Wireshark to analyze the packets that my browser sent and the ones that were sent through Java, I found a big difference:

https://i.stack.imgur.com/n8OvR.png

https://i.stack.imgur.com/zPBPR.png

(open links to view the images)

When I send HTTP POST/GET, the tool that I am using (either a browser or Java) sends information about itself. However, I want to send EXACTLY the same packet through Java as I would through a browser. Is there a way to do it? How can I hide the sender (in this case Java) information? Thank you!

user1094565
  • 9
  • 3
  • 5
  • 1
    Looks like your looking for http://stackoverflow.com/questions/2529682/setting-user-agent-of-a-java-urlconnection – havexz May 22 '12 at 17:33

2 Answers2

1

Sorry but the only good answer on the other page is at the bottom.

setRequestProperty("User-Agent", ""); see the JDocs for URLConnection

You can also use this for any of the other headers such as Accept-Language. Be careful if you set the Accept-Encoding as that may cause the server to gzip something which Java will not handle correctly and you will need to do something like this.

I am not sure why the are suggesting to set a system property.

Community
  • 1
  • 1
Krrose27
  • 1,026
  • 8
  • 13
0

If you want to send exactly the same packets using pure Java, well, you can't.

But this library might help: http://www.savarese.com/software/rocksaw/

Samuel Edwin Ward
  • 6,526
  • 3
  • 34
  • 62