HttpClient获取android时发生缓冲区溢出错误
我正在尝试使用android中的HttpClient从远程站点获取资源。我一直在尝试以下方法HttpClient获取android时发生缓冲区溢出错误,android,httpclient,Android,Httpclient,我正在尝试使用android中的HttpClient从远程站点获取资源。我一直在尝试以下方法 public class Engine { public String test(){ String engineUrl = "http://site/path"; //I used legit site and path here InputStream is = null; String result = ""; try{
public class Engine {
public String test(){
String engineUrl = "http://site/path"; //I used legit site and path here
InputStream is = null;
String result = "";
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet req = new HttpGet(engineUrl);
HttpResponse response = httpclient.execute(req); <<----this
//is = response.getEntity().getContent();
}catch(Exception e){
e.printStackTrace();
Log.e("error", "err");
}
return result;
}
无论如何谢谢你
谢谢大家,我想我解决了这个问题。我必须将AsyncTask用于网络操作,而不是线程类。再次感谢您不能打电话
v.setText(e.test())
在
因为UI更改必须在UI线程中完成。试一试
final String result = e.test():
runOnUiThread(new Runnable(){
private void run (){
v.setText(result);
}
}).
您尝试下载的资源有多大?对于大型下载,我建议使用DownloadManager:它非常小,大约100-150个ascii字母。好的,BufferOverflowException正好抛出在httpclient.execute(req)的行上?或者别的地方?是的!当我把它评论出来时,它工作得很好。就在httpclient.execute(req)上,我使用了权限INTERNET和访问网络状态。我希望他们能胜任这项工作?
run().
final String result = e.test():
runOnUiThread(new Runnable(){
private void run (){
v.setText(result);
}
}).