» 首頁 » 討論區 » Android程式設計 »透過POST和網頁交換中文亂碼

透過POST和網頁交換中文亂碼

發表人: 訪客
發表時間: 2012-08-29 23:41:27
vtext.setText("Runing...");
/* Post Http Data */
String SyncURL="http://localhost";
String response;
HttpPost hp = new HttpPost(SyncURL);
HttpResponse hr;

List <NameValuePair> params = new ArrayList <NameValuePair>();
//Add Post Data
params.add(new BasicNameValuePair("data","Send...@@"));
params.add(new BasicNameValuePair("text","中文"));
try {
UrlEncodedFormEntity urf = new UrlEncodedFormEntity(params,HTTP.UTF_8);
hp.setEntity(urf);
hr = new DefaultHttpClient().execute(hp);
if(hr.getStatusLine().getStatusCode()==200){
response=EntityUtils.toString(hr.getEntity());
vtext.setText(response);
}else{
vtext.setTag("Error State:"+hr.getStatusLine().toString());
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
vtext.setText("Error..."+e.toString());
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
vtext.setText("Error..."+e.toString());
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
vtext.setText("Error..."+e.toString());
e.

如上...我按照上面的方法是過後....在eclipse 的方面 中文部分卻出現亂碼,這是為什麼 ?! 有哪裡需要改嗎 ?!