Mdevlin
Mdevlin

Reputation: 1

Android BufferedReader is redirected

I need to read in a webpage using a BufferedReader. When I run the code snippet as a Java application on my computer it works fine. However when I run the code on the phone, the BufferedReader is redirected to the wrong webpage. How can I stop the BufferedReader from being redirected?

The page I am trying to visit is a youtube account's subscribers. I can view the page on my computer just fine, but not on my phone.

Upvotes: 0

Views: 194

Answers (1)

Snicolas
Snicolas

Reputation: 38168

As a web server can identify the browser / platform used to request a page by using the "user agent string", you must change the user agent of the jdk before downloading the web page from your java file. You should add this line to your java program :

System.setProperty( "user.agent" , <user agent string from your browser > );

you acn find a lot of user agent strings here. Pick one that is not associated to a mobile platform like :

Mozilla/5.0 (X11; Linux x86_64; rv:2.2a1pre) Gecko/20110324 Firefox/4.2a1pre

Regards, Stéphane

Upvotes: 1

Related Questions