我尝试在 Android 中下载网站源时遇到问题。
EditText textbox = (EditText) findViewById(R.id.editText1);
URL link;
HttpURLConnection httpcon;
String wynik;
try
{
link = new URL("http://stackoverflow.com/faq"); //example site
httpcon = (HttpURLConnection) link.openConnection();
httpcon.connect();
InputStream inpText = null;
inpText = link.openStream();
byte[] bText = new byte[httpcon.getContentLength()];
int readSize = inpText.read(bText);
wynik = new String(bText);
httpcon.disconnect();
inpText.close();
textbox.append(wynik);
}
catch(Exception e)
{
//
}
当我在 AVD 2.2 上运行此代码时,文本框包含所有网站源代码,但是当我在我的手机上使用 Android 2.3.5(或 ADV 2.3.3)运行此代码时,文本框仅包含几行。
它看起来完全像这样:
我的手机 = 1012 字节:
<title>Frequently Asked Questions - Stack Overflow</title> <link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico"> <link rel="apple-touch-icon" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript" src="http://cdn.sstatic.net/js/stub.js?v=8a629d6e9fb6"></script> <link rel="stylesheet" type="text/css" href="http://cdn.sstatic.net/stackoverflow/all.css?v=645537e2c00d"> <script src="http://cdn.sstatic.net/Js/help.js?v=fc9fb0517db2" type="text/javascript"></script> <script type="text/javascript"> StackExchange.ready(function() { StackExchange.help.init({ host: 'stackoverflow.com', bgColor: '#FFF', bg
ADV 2.2 = 50 984 字节
我究竟做错了什么?
提前谢谢你,对不起我的英语。帕特里克