aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes Making HttpURLConnection look like MS Explorer/firefox/opera etc Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Making HttpURLConnection look like MS Explorer/firefox/opera etc" Watch "Making HttpURLConnection look like MS Explorer/firefox/opera etc" New topic
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
    
  13

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
    
  13

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
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Making HttpURLConnection look like MS Explorer/firefox/opera etc
 
Similar Threads
Download a binary file programmatically?
make a network call to an website?
Use Servlet to read a webpage.
HttpURLConnection seems to be doing some level of URL Decoding.
Redirect from servlet to EXTERNAL URL using POST