1

我正在使用http://loopj.com/android-async-http/库与 Web 服务器进行交互。

我正在发送 POST 请求并获得带有 200 状态码(Ok)的空响应。

但是在检查与 Fiddler 的连接后,我发现我收到 400 BAD REQUEST 错误

如果我尝试 GET 请求 - 一切都会好起来的

UPD:我找到了问题来源 - 我的 base64 参数(“数据”)以某种方式发生了变化。我的代码生成了有效的 base64 字符串,但在请求中添加了“0%3D%0A”,使其无法验证

我的 POST 请求:

POST http://example.com HTTP/1.1
Content-Length: 143
Content-Type: application/x-www-form-urlencoded
Host: example.com
Connection: Keep-Alive
User-Agent: android-async-http/1.4.1 (http://loopj.com/android-async-http)
Accept-Encoding: gzip

hash=123&data=123

我的回复:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at example.com Port 80</address>
</body></html>

安卓代码:

public class RestClient {
     private static final String BASE_URL = "http://example.com";

      private static AsyncHttpClient client = new AsyncHttpClient();

      public static void post(RequestParams params, AsyncHttpResponseHandler responseHandler) {
          client.post(BASE_URL, params, responseHandler);

      }


}

public static void register(String login, String email, String password,
            final RegisterProcessListener listener) {

        String base64 = Cryptography
                .credentialsToBase64(login, email, password);
        String md5 = Cryptography.Base64toMD5(base64);
        RequestParams params = new RequestParams();
        params.put(DATA, base64);
        params.put(HASH, md5);

        RestClient.post(...)

提前感谢您的帮助

4

0 回答 0