當我運行這段代碼時,我總是收到一個「空」異常。如果我手動輸入url字符串到我的瀏覽器中,PHP腳本發佈「{query_result:SUCCESS}」表示它已經工作,但是當我通過這段代碼嘗試時,我只是將Exception e視爲「null」。誰能幫忙?使用HttpURLConnection,InputStreamReader,我得到空響應
protected String signUp(String username) {
String link = "http://12.34.56.78/JSON_addUser.php";
String data = "";
BufferedReader bufferedReader;
String result = "";
String message;
try {
data += "?username=" + URLEncoder.encode(username, "UTF-8");
link += data;
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
result = bufferedReader.readLine();
return result;
} catch (Exception e) {
message = "Exception trying: " + link + " Got: " + e.getMessage() + result;
return message;
}
}
異常發生在哪一行?請生成並顯示整個堆棧跟蹤。我暫時不在乎http://stackoverflow.com/q/218384/616460。 –
您能否提供錯誤日誌請 –
^確保您修改您的代碼以首先將錯誤日誌轉儲到錯誤日誌。 –