我在android studio中使用该代码来阅读这个(" http://www.posh24.com/celebrities")网站,但它只读了它到达此页后它停止的源页面的几行字符串"
</div>
<div class="channelListEntry">
<a href="/justin_bieber">
<div clas
&#13;
这是代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GetString getString = new GetString();
String gr = null;
try {
gr = getString.execute("http://www.posh24.com/celebrities").get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
和
public class GetString extends AsyncTask<String,Void,String> {
protected String doInBackground(String... params) {
String result = "";
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
int data = reader.read();
while (data != -1) {
char current = (char) data;
result += current;
data = reader.read();
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}