How to solve the problem of garbled code in HTTP request in Android
Today Xiaobian to share with you Android HTTP request Chinese garbled how to solve the relevant knowledge points, detailed content, clear logic, I believe most people are still too familiar with this knowledge, so share this article for your reference, I hope you have read this article after harvest, let's learn about it together.
HTTP request Chinese garbled solution in Android
coding parameters
List formparams = new ArrayList(); //Request parameters for (NameValuePair p : params) { formparams.add(p); } UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams,HTTP.UTF_8); //Create POST request HttpPost httppost = new HttpPost(url); httppost.setEntity(entity);
Android sends HTTP requests, Android default encoding is utf-8.
Problem Description:
The request has been set to UTF-8 in the above code, and the code in the server is also all UTF-8, but the server obtains Chinese or garbled.
Since the server side is not developed by itself, it is impossible to see how the server works, only that the encoding is UTF-8.
The same server, iPhone client sends Chinese without garbled code.
Problem solving:
Try printing the HTTP header for Android,iPhone.
The content-types are different.
Andorid :content-type:application/x-www-form-urlencoded;IPHONE:content-type:application/x-www-form-urlencoded; charset=utf-8
So try to add a header to the request
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset= utf-8"); The above is "Android HTTP request Chinese garbled how to solve" All the content of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.