私はサーバーからの応答を要求しようとしていますが、 "HttpResponse response = client.execute(request);"を使用すると、プログラムは例外ケースに入ります。ここでHttpResponseを使用中に例外を取得するresponse = client.execute(request);
は私のコードです:
機能サーバからの応答を取得するため
パブリック文字列executeHttpGet(文字列名、文字列のパスワード)の活動に使用される例外{
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 bloを入力しますck!
私を助けてください! thxで事前に!
例外を記録してください(http://developer.android.com/reference/android/util/Log.htmlを参照)、あなたの質問にスタックトレース全体を追加してください。つまり、インターネットのアクセス許可が不足している可能性があります(http://developer.android.com/reference/android/Manifest.permission.html#INTERNETを参照)。 – Mike