下面的代碼未接收到PHP文件,該文件是「羽毛球協會」從這段代碼的PHP文件的輸出:的AsyncTask HTTP錯誤
print(json_encode($row['Description']));
這將是巨大的,如果有人可以當場錯誤。 「結果」和「是」都是空變量:
public class BackgroundAsyncTask extends AsyncTask<Void, String, Void> {
protected Void doInBackground(Void... params) {
//http post
try{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://ntusocities.host22.com/post.php");
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
} catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try {
JSONObject userObject = new JSONObject(result);
info = userObject.getString("Description");
}
catch(Exception ex){
}
return null;
}
}
非常感謝!
你準確得到了什麼錯誤? – 2013-04-10 17:15:45
檢查您的PHP腳本提供的響應,以確保數據正在返回。嘗試在瀏覽器中運行腳本以檢查數據是否正在傳遞。 – kabuto178 2013-04-10 17:17:52
@ kabuto178我在瀏覽器中運行了PHP,得到的結果是它不會記錄在應用程序中 – Ryaller 2013-04-10 17:21:05