HttpServiceClient (Apache) を使用して特殊文字を含む文字列を送信する際の UTF-8 エンコーディングについて質問があります。
以下に、メソッドが文字列を受け取り、Http 経由で送信する小さなコードを示します (コードでは完全ではありません)。
デコードされた文字列は問題なく動作しているように見えますが、method.addparameter または httpClient.execute(method) が文字列を再度エンコードするかどうかを知りたいです。クライアント側で文字列が二重にエンコードされているように見えるという問題があります。
例えば。strReq = äöü
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.httpclient.methods.PostMethod;
public class Demo {
public static void Test(String strReq) throws CancellationException, IOException, DecoderException {
PostMethod method = null;
method = new PostMethod("www.example.com");
// Encode the XML document.
URLCodec codec = new URLCodec();
String requestEncoded = new String(strReq);
try {
requestEncoded = codec.encode(strReq);
} catch (EncoderException e) {
}
System.out.println("encoded req = "+requestEncoded);
method.addParameter(Constants.Hdr, requestEncoded);
String str2 = codec.decode(requestEncoded);
System.out.println("str2 ="+str2);
}