使用错误的编码发送 android 中的 post

Sending a post in android with bad encoding

我正在从 android 向服务器发送 post 内容。 问题是服务器的数据到达错误,编码问题,例如“{”到达为“%7B%”。

这是来自 android 的代码:

 RequestParams params = new RequestParams();

    params.put("alta", "{s}");
String ruta = "http://www.something.com/receive";
client.post(ruta, params,
        new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) {

            }
        }

服务器部分正在接收此数据,例如:

$data = $this->request->data;
$data =file_get_contents('php://input');

您需要使用 URLEncoder.encode(...) 您请求的数据部分。 在服务器 URL 对其进行解码。

你应该没事的。

这个问题与文本编码本身没有直接关系。

docs for RequestParams, text values are directly included in the url. As all text that is included in URLs has to be encoded to only include characters that are allowed in URLs (ASCII), text is url encoded可以看出。

AsyncHttpClient 会自动在后台进行编码,因此您会在 php 端收到编码形式的字符串。

为了得到您发送的原文,您可以使用php端的rawurldecode()urldecode()函数对您收到的编码字符串进行解码