gpt4 book ai didi

java - @ 在 HTTPPost 请求中转换为 %40

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:04 26 4
gpt4 key购买 nike

我正在尝试向网络服务发送发布请求..当我在参数中添加特殊字符 @ 时,它被转换为 %40。我检查了服务器端。他们得到的是 %40 而不是 @。谁能帮我??这是我的代码..

httpclient = new DefaultHttpClient();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Email", "abc@gmail.com"));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost,responseHandler);

我也试过这种方法来防止我的参数编码。

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.PLAIN_TEXT_TYPE));

但它引发了不支持的编码算法

请帮我解决这个问题。

最佳答案

您正在使用 UrlEncodedFormEntity,它将 URL-encode内容。使用此编码,将 @ 转换为 %40 是正常的。收件人应该能够自动解码,尽管您可能必须为此使用正确的内容类型,可能是 application/x-www-form-urlencoded

关于java - @ 在 HTTPPost 请求中转换为 %40,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9193078/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com