Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Making HttpURLConnection look like MS Explorer/firefox/opera etc  RSS feed

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am looking to develop solution that makes a connection to a web site server with HttpURLConnection look like one of the common browsers.

Is this possible by modifying the headers etc?

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "look like"?
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well web site stats will show what browsers are looking at your site, using a site I have for example.

1. MSIE 1,673
2. Netscape (compatible) 82
3. Firefox 42
4. Safari 7
5. Yeti 4

Using HttpURLConnection it will come up as 'Java VM direct socket connection' or something similar, I would like to configure my application to fool the server into believing that it is MSIE.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just do this:

HttpURLConnection connect = (HttpURLConnection) someURL.openConnection();
connect.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5");
 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh, thank you.

I knew it could be done, I just could not find anything on internet.

Searching on criteria like java, browser, connection, header, mozilla would bring back half the web

Cheers
 
Regina Thomas
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a recent problem with access a url from a Java servlet because it was not a browser. Thanks for this tidbit.

Q...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!