HttpClient post提交請求亂碼問題解決

 HttpClient post提交請求亂碼問題解決

第一種:

HttpPost post=new HttpPost(url);

StringEntity content=new StringEntity(data, Charset.forName("utf-8"));// 設置編碼

content.setContentType("application/json; charset=UTF-8");

content.setContentEncoding("utf-8");

post.setEntity(content);

第二種:

httpPost.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));//在設置請求數據的時候,指定編碼。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章