Author
Making HttpURLConnection look like MS Explorer/firefox/opera etc
David Rocks
Ranch Hand
Joined: Apr 24, 2001
Posts: 160
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
Joined: Jan 10, 2002
Posts: 56202
What do you mean by "look like"?
[Smart Questions ] [JSP FAQ ] [Books by Bear ] [Bear's FrontMan ] [About Bear ]
David Rocks
Ranch Hand
Joined: Apr 24, 2001
Posts: 160
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
Marshal
Joined: Jul 08, 2003
Posts: 24057
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");
[Jess in Action] [AskingGoodQuestions]
David Rocks
Ranch Hand
Joined: Apr 24, 2001
Posts: 160
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
Joined: May 12, 2006
Posts: 11
posted Jan 04, 2009 10:29:17
0
I had a recent problem with access a url from a Java servlet because it was not a browser. Thanks for this tidbit.
Q...
WiredPages | Remix
subject: Making HttpURLConnection look like MS Explorer/firefox/opera etc