如何从Android应用程序了编程连接一个完整的网站,而不是移动 [英] How to connect a full web site rather than mobile programmatically from android applicaiton

查看:115
本文介绍了如何从Android应用程序了编程连接一个完整的网站,而不是移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以连接到一个完整的网站,而不是移动网页从code?为什么我问这个的原因是,当我尝试连接一个网站里面有一个手机网站,它引导到移动页面,所以我不能得到完整的网站的内容。

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 connect 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.

我使用这个code连接到网站,但我想两个或三个不同code来连接所有的人都没有工作。

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();

感谢

推荐答案

尝试例如设置适当的头属性像这样的:

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");

这篇关于如何从Android应用程序了编程连接一个完整的网站,而不是移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆