【问题标题】:HttpPost encoding to windows-1255 add 25 to each charHttpPost 编码到 windows-1255 为每个字符添加 25
【发布时间】:2015-01-29 13:27:12
【问题描述】:

我尝试使用 httpPost 向服务器发送数据。 它看起来像这样:

String username = URLEncoder.encode("myUsername","windows-1255");
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("****");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("username", username));
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);

但它以 %25XX 而不是 %XX 的形式发送到服务器字符。 为什么会这样?

【问题讨论】:

  • 它是 %。更多bla bla bla
  • 这不是答案。每个 %## 代表一个 url 编码字符。请了解。请准确说出您发送的字符串和收到的字符串。
  • 我的意思是解码后%是%25
  • 不要先对用户名进行编码,因为所有用户名都将使用 new UrlEncodedFormEntity() 进行编码。
  • 我需要这样做,因为我将它作为字符集 windows-1255 发送。无论如何我找到了解决方案。感谢您的帮助

标签: android http-post httpclient


【解决方案1】:

我需要将实体添加为字符串而不是列表:

String param="username"+username;
post.setEntity(new StringEntity(param));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2012-09-29
    • 2012-11-13
    • 1970-01-01
    相关资源
    最近更新 更多