HttpUrlConnection拋出FileNotFound異常,其中json對象在DataOutputStream中傳遞。如何解決這個問題? 爲什麼拋出FileNotFound異常?HttpUrlConnection POST請求拋出FileNotFound異常,如何解決此錯誤?
public final String apiCall(String pUrl,JSONObject jsonObject) {
try {
URL url = new URL(pUrl);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setDoOutput(true);
httpURLConnection.connect();
DataOutputStream wr = new DataOutputStream(httpURLConnection.getOutputStream());
wr.writeBytes(jsonObject.toString());
wr.flush();
wr.close();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
try{
StringBuilder stringBuilder = new StringBuilder();
String line;
while((line = bufferedReader.readLine())!= null) {
stringBuilder.append(line);
}
return stringBuilder.toString();
} catch (Exception e) {
return "ERROR";
} finally{
bufferedReader.close();
httpURLConnection.disconnect();
}
}catch (Exception e) {
return "ERROR";
}
}
哪一行拋出這個錯誤?發佈完整的logcat – Denny
最後一次拋出異常 –
我已添加登錄最後一個catch塊...其中異常e顯示該異常 –