好吧,所以我的HttpClient
調用不工作在java android我試圖用try和catch來包圍它,並且它保持失敗。請幫忙!!!android java Httpclient連接
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
URI ur = new URI("http://192.168.1.10/test/randomy/generate/index.php");
HttpGet request = new HttpGet();
request.setURI(ur);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String l = "";
StringBuffer sb = new StringBuffer("test");
while((l=in.readLine())!=null){
sb.append(l);
}
in.close();
return sb.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
if(in!=null){
try {
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return "Error";
}
你得到什麼錯誤?您是否在清單文件中添加了互聯網許可? – GrIsHu
是的,我做到了。但你如何閱讀錯誤? – Sam
是在瀏覽器中工作的鏈接。當您在瀏覽器中點擊該鏈接時,您是否嘗試獲得響應> – VVB