以下は、AndroidアプリでSOAPリクエストを送信するために使用しているコードで、1つを除くすべてのリクエストで正常に機能します。このコードはIOExceptionをスローします:変数に漢字がある場合にContent-lengthを超えました。wr.flush();
requestBody
その場合のコンテンツの長さは409
URL url = new URL(Constants.HOST_NAME);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Modify connection settings
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setRequestProperty("SOAPAction", soapAction);
String requestBody = new String(soapRequest.getBytes(),"UTF-8");
int lngth = requestBody.length();
connection.setRequestProperty("Content-Length", (""+lngth));
// Enable reading and writing through this connection
connection.setDoInput(true);
connection.setDoOutput(true);
// Connect to server
connection.connect();
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
wr.write(requestBody);
wr.flush();
wr.close();
文字列に漢字がある場合、何が問題になっているのでしょうか。
編集:「content-lenght」ヘッダーフィールドを削除しましたが、機能しますが、なぜですか?