私は解決できないように見える HttpsURLConnection に問題があります。基本的に、私はいくつかの情報をサーバーに送信しています。そのデータの一部が間違っている場合、サーバーは 500 応答コードを送信します。ただし、応答で、データのどのビットが間違っていたかを知らせるメッセージも送信します。問題は、メッセージを読み込んだときにメッセージが常に空であることです。これは、ストリームを読み取る前に常に filenotfound 例外がスローされるためだと思います。私は正しいですか?エラーストリームも読み込もうとしましたが、これは常に空です。ここにスニペットがあります:
conn = (HttpsURLConnection) connectURL.openConnection();
conn.setDoOutput(true);
conn.setConnectTimeout(30000);
conn.setReadTimeout(30000);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Length",
Integer.toString(outString.getBytes().length));
DataOutputStream wr = new DataOutputStream(conn
.getOutputStream());
wr.write(outString.getBytes());
wr.flush();
wr.close();
if(conn.getResponseCode>400{
String response = getErrorResponse(conn);
public String getErrorResponse(HttpsURLConnection conn) {
Log.i(TAG, "in getResponse");
InputStream is = null;
try {
//is = conn.getInputStream();
is = conn.getErrorStream();
// scoop up the reply from the server
int ch;
StringBuffer sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char) ch);
}
//System.out.println(sb.toString());
return sb.toString();
// return conferenceId;
}
catch (Exception e){
e.printStackTrace();
}
}