When the project submits data to the server in HttpPost mode, Chinese characters on the server display garbled characters. How can this problem be solved? In fact, this problem should be taken into account in the architecture. If it involves different platform applications, we should try to use UTF8 encoding as much as possible, which can be less troublesome. Of course, you can specify the encoding when you post data. refer to the following functions:
·
[Java] public Map <String, Object> CreateNote (int albumId, String title,
String remark ){
String noteId = "";
Map <String, Object> map = new HashMap <String, Object> ();
Try {
HttpParams parms = new BasicHttpParams ();
Parms. setParameter ("charset", HTTP. UTF_8 );
HttpConnectionParams. setConnectionTimeout (parms, 8*1000 );
HttpConnectionParams. setSoTimeout (parms, 8*1000 );
HttpClient httpclient = new DefaultHttpClient (parms );
HttpPost httppost = new HttpPost (ConfigHelper. CreateUri );
Httppost. addHeader ("Authorization", mToken );
Httppost. addHeader ("Content-Type", "application/json ");
Httppost. addHeader ("charset", HTTP. UTF_8 );
JSONObject obj = new JSONObject ();
Obj. put ("title", title );
Obj. put ("categoryId", mCategoryId );
Obj. put ("sourceUrl", GetSourceUri ());
JSONArray arr = new JSONArray ();
Arr. put (DateFormat. format ("yyyyMM", Calendar. getInstance (Locale. CHINA )));
Obj. put ("tags", arr );
Obj. put ("content", remark );
Httppost. setEntity (new StringEntity (obj. toString (), HTTP. UTF_8 ));
HttpResponse response;
Response = httpclient.exe cute (httppost );
Int code = response. getStatusLine (). getStatusCode ();
If (code = ConstanDefine. ErrorCode. SuccOfHttpStatusCode ){
String rev = EntityUtils. toString (response. getEntity ());
Obj = new JSONObject (rev );
NoteId = obj. getString ("id ");
Map. put ("return_code", "0 ");
Map. put ("content", rev );
}
} Catch (Exception e ){
If (map. containsKey ("return_code ")){
Map. remove ("return_code ");
}
Map. put ("return_code", "1 ");
}
Return map;
}
From the pure soul