对windows-1255的HttpPost编码为每个char添加25

时间:2015-01-29 13:27:13

标签: android http-post httpclient

我尝试使用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);

但它发送到服务器char为%25XX而不是%XX。 为什么会这样?

1 个答案:

答案 0 :(得分:0)

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

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