0
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Accept", "application/json");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(data.toString());
wr.flush();
status = con.getResponseCode();
此代碼是Android Studio中的AsyncTask類的一部分。當我使用PostMan執行Post請求時,返回的狀態是200;但是,當我使用android模擬器發出請求時,狀態將返回爲0.我感到非常困惑,並且需要一些幫助。在AsyncTask中調用HttpUrlConnection.getResponseCode()時獲取狀態碼0
我有上網權限和連接;當我執行POST請求時,數據被正確發送(它正確地發送到數據庫)。但是,狀態碼返回爲0。 –