如何设置编码为HTTP POST请求的android [英] How to set Encoding to Http Post request android
本文介绍了如何设置编码为HTTP POST请求的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置了 UTF
编码 HTTP POST
请求?
下面是我的code片段。
的HttpClient HttpClient的= getNewHttpClient(); 字符串USER_AGENT =(字符串)httpClient.getParams()的getParameter(
CoreProtocolPNames.USER_AGENT)
+Android的;
httpClient.getParams()的setParameter(CoreProtocolPNames.USER_AGENT,
用户代理);
httpClient.getParams()。setBooleanParameter(
http.protocol.expect-继续,FALSE);
HTT presponse响应;
HttpPost后=新HttpPost(remoteUrl);
的System.out.println(URL:+ remoteUrl +值
+ nameValuePair.toString());
post.setEntity(新UrlEn codedFormEntity(的NameValuePair));
响应= httpClient.execute(岗位);
。INT postStatus = response.getStatusLine()的getStatus code();
字符串结果= EntityUtils.toString(response.getEntity());
的System.out.println(结果:+结果);
解决方案
您可以通过拨打设置的任何头 post.setHeader(头名,标头值);
在你的情况应该是
post.setHeader(接收字符集,UTF-8);
How can i set the UTF
encoding to Http Post
request?
Here is my code snippet.
HttpClient httpClient = getNewHttpClient();
String user_agent = (String) httpClient.getParams().getParameter(
CoreProtocolPNames.USER_AGENT)
+ " Android";
httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
user_agent);
httpClient.getParams().setBooleanParameter(
"http.protocol.expect-continue", false);
HttpResponse response;
HttpPost post = new HttpPost(remoteUrl);
System.out.println("Url:" + remoteUrl + " values:"
+ nameValuePair.toString());
post.setEntity(new UrlEncodedFormEntity(nameValuePair));
response = httpClient.execute(post);
int postStatus = response.getStatusLine().getStatusCode();
String result = EntityUtils.toString(response.getEntity());
System.out.println("result:" + result);
解决方案
You may set any header by calling
post.setHeader("HEADER NAME","HEADER VALUE");
In your case it should be
post.setHeader("Accept-Charset","utf-8");
这篇关于如何设置编码为HTTP POST请求的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文