1. 程式人生 > >關於使用httpclient傳輸json資訊並解決中文亂碼問題

關於使用httpclient傳輸json資訊並解決中文亂碼問題

private void sendInfo3(LoanVO vo) throws Exception{
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
List<NameValuePair> pares = new ArrayList<NameValuePair>();
pares.add(new BasicNameValuePair("phone", vo.getApplyMobile()));
String v=new String(vo.getApplyName().getBytes("UTF-8"),"ISO-8859-1");
String name =new String(v.getBytes("ISO-8859-1"),"UTF-8");
pares.add(new BasicNameValuePair("name",name));
pares.add(new BasicNameValuePair("channelid","huicongwang"));
pares.add(new BasicNameValuePair("isSubmit","true" ));
pares.add(new BasicNameValuePair("source","addLeadsApi" ));
pares.add(new BasicNameValuePair("productType","PTD" ));
pares.add(new BasicNameValuePair("fromLeadsId",vo.getId().toString()));
HttpPost request = new HttpPost(LUFAX_URL);
request.setEntity(new UrlEncodedFormEntity(pares, HTTP.UTF_8));
HttpResponse response = new DefaultHttpClient().execute(request);
HttpEntity result = response.getEntity();
String retSrc = EntityUtils.toString(response.getEntity());// 生成 JSON 物件
System.out.println("-----------"+response.getEntity().toString()+"------"+response.getEntity().getContentLength());
logger.warn("返回結果"+retSrc+"-----------------------------------------------");

}