Vinoth Selvaraj
Vinoth Selvaraj

Reputation: 301

Simulating Mobile Web Browser from java program

I am trying to load a mobile version of the web page using a java program for extracting few information from the web page, easily.

In Firefox, after adding the user agent switcher plugin, i have added a new user agent with the value

"Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE71-1/110.07.127; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413"

After this, if i try to load http://www.bbc.co.uk/, the mobile version of the web page is loaded successfully.

But i am trying to do the same with a java program using apache httpclient library by setting the User-Agent as given below:

HttpClient httpclient = new DefaultHttpClient();

HttpProtocolParams.setUserAgent(httpclient.getParams(),
  "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaE71-1/110.07.127; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413");

But i am not getting the mobile version of the the same link.

I hope the redirect will happen automatically here and i will be getting the mobile version of the page as the user-agent is modified.

Can you please help me to resolve this issue?

Upvotes: 2

Views: 735

Answers (2)

fglez
fglez

Reputation: 8552

HttpClient does not support JavaScript redirection.

Please note that HttpClient is not a browser. Importantly it lacks UI, cache, HTML renderer and a JavaScript engine. To learn more about the scope of HttpClient please refer to HttpClient Primer

Maybe you can try solutions proposed in these questions

Upvotes: 1

cpater
cpater

Reputation: 1099

Had you setFollowRedirects on HttpClient?

Upvotes: 0

Related Questions