【发布时间】:2011-07-14 16:30:39
【问题描述】:
我正在尝试从服务器请求响应,但是当我使用“HttpResponse response = client.execute(request);”时,程序进入了异常情况。
这是我的代码:
从服务器获取响应的函数
public String executeHttpGet(String username, String password) throws Exception {
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://emapzoom.com/setting/device_login"+ "?device_id=" +password+ "&login_name="+ username));
HttpResponse response = client.execute(request);
in = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
return page;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
活动中使用的代码
try{
test=executeHttpGet(name,pass);
}catch(Exception e){
}
当我执行时,程序进入catch块!
请帮帮我!!! 提前谢谢!
【问题讨论】:
-
请记录异常(参见developer.android.com/reference/android/util/Log.html)并将整个堆栈跟踪添加到您的问题中。也就是说,它可能只是缺少 INTERNET 权限(请参阅developer.android.com/reference/android/…)。
标签: android exception httpresponse