How can I connect to a full web site rather than mobile web page from code? The reason why I ask this is when I try to conn开发者_StackOverflowect a web site which has a mobile web site, it directs to mobile page so I can't get the content of the full site.
I'm using this code to connect to site but I tried two or three different code to connect all of them didn't work.
URL url = new URL(adress);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
Thanks
try to set proper header properties e.g. like this:
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setRequestProperty("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
conn.setRequestProperty("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
conn.setRequestProperty(
"User-Agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0");
conn.setRequestProperty("Accept-Language", "en-gb,en;q=0.5");
conn.setRequestProperty("Referer", "http://youtube.com");
conn.setRequestProperty("Accept-Encoding", "deflate");
精彩评论