Android HTTP POST - 400 BAD REQUEST

时间:2013-08-12 12:54:16

标签: android apache http

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

我发送POST请求并获得200状态代码的空响应(确定)。

但在检查与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>

Android代码:

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(...)

提前感谢您提供任何帮助

0 个答案:

没有答案