1
私はokhttpを使ってJSONを既存のサービスに送信する投稿要求を作成しようとしています。しかし、これまでにフォームを送信しようとすると、okhttpはJSONのすべての特殊文字をエスケープしますが、サーバーはエスケープされていないものだけを受け入れるようにコーディングされています。それをWiresharkを使ってOKhttp不要なフォームデータのエスケープ
String msg = "{SomeJsonMsg:...}";
FormEncodingBuilder b = new FormEncodingBuilder();
b.addEncoded(msg, "");
RequestBody form_body = b.build();
(すなわちGOODコール)を再コードをしようとしているアプリのIMのために、以下の例を示します
[email protected]+2JPe NGnPPOST /pp/httpService.do HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9500 Build/KOT49H)
Host: test.com
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Type: application/x-www-form-urlencoded
Content-Length: 213
{"callPara": {"userPassword":"password!","userName":"myname","gameName":"SGZJ-ANDROID-SG","udid":"d5d96bcc3a8e436ab991d35eb284d6bd","clientType":"EN","releaseChannel":"EN","locale":"EN"},"serviceName":"login"}
が、Javaコードは、上記の本(BADコール)をダンプします。
[email protected]+2J,P ^FPPOST /pp/httpService.do HTTP/1.1
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9500 Build/KOT49H
Content-Type: application/x-www-form-urlencoded
Content-Length: 324
Host: test.com
Connection: Keep-Alive
Accept-Encoding: gzip
%7B%22callPara%22%3A%7B%22userPassword%22%3A%22password%21%22%2C%22userName%22%3A%22myname%22%2C%22gameName%22%3A%22SGZJ-ANDROID-SG%22%2C%22udid%22%3A%226d49ee067762822c6a8f721d256ce44c%22%2C%22clientType%22%3A%22EN%22%2C%22releaseChannel%22%3A%22EN%22%2C%22locale%22%3A%22EN%22%7D%2C%22serviceName%22%3A%22login%22%7D=
okhttpを使用してこれを行うにはどうしますか?私はb.add(msg、 "")とb.addEncoded(msg "")を試しました.2人の違いについては実際には分かりません。