HttpUrlConnection throw 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";
}
}
このエラーがスローされますどのようなライン? – Denny
最後にcatch catch例外を投げる –
最後のcatchブロックにログを追加しました...例外の例外を示す例外 –