我正在安装android工作室的应用程序,我比较新,我正试图从网站上提取一些信息。但我遇到了一个问题。我的代码似乎坚持我的HttpResponse请求。我已经加载了大量的调试日志,最后一个要打印的是“Log.v(”ARG“,”Trying 2“);”。我已经在下面提供了适用的代码,任何人都可以指出我做错了吗?非常感谢任何帮助。
@Override
protected String doInBackground(String... medURLs) {
Log.v("ARG", "Executed");
String medName = "medName";
for (String medSearchURL : medURLs) {
HttpClient medClient = new DefaultHttpClient();
Log.v("ARG", medSearchURL);
try {
Log.v("ARG", "Trying 1");
HttpGet medGet = new HttpGet(medSearchURL);
Log.v("ARG", "Trying 2");
HttpResponse medResponse = medClient.execute(medGet);
Log.v("ARG", "Trying 3");
StatusLine medSearchStatus = medResponse.getStatusLine();
Log.v("ARG", "before if");
if (medSearchStatus.getStatusCode()==200) {
HttpEntity medEntity = medResponse.getEntity();
InputStream medContent = medEntity.getContent();
InputStreamReader medInput = new InputStreamReader(medContent);
BufferedReader medReader = new BufferedReader(medInput);
Log.v("ARG", "In if statement");
String lineIn;
while ((lineIn=medReader.readLine())!=null) {
medName +=lineIn;
Log.v("ARG", "In while loop");
}
}
else{
Log.v("ARG", "failed if statement");
}
}
catch(Exception e){
e.printStackTrace();
Log.v("ARG", "caught");
}
Log.v("ARG", "End of big loop");
}
Log.v("ARG", "About to return");
return medName;
}
答案 0 :(得分:0)
我认为你应该尝试httpurlconnection。你可以查看本教程之一..
http://www.tutorialspoint.com/android/android_network_connection.html http://www.vogella.com/tutorials/AndroidNetworking/article.html