我用 HttpPost 擷取網路回傳的資料
可是中文字的部分都變成亂碼了
我 Google 好幾天
也都照著設定過
可是還是亂碼
要怎麼修改才可以解決問題呢?
謝謝
程式碼如下:
-------------------------------------------------------------------
new Thread() {
@Override
public void run() {
HttpPost httpRequest = new HttpPost("http://140.121.196.8/WS/login.php");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("account", account.getText().toString()));
params.add(new BasicNameValuePair("password", password.getText().toString()));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == 200){
final String result = EntityUtils.toString(httpResponse.getEntity());
runOnUiThread (new Runnable() {
public void run() {
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
});
}
else
Toast.makeText(MainActivity.this, "回傳失敗", Toast.LENGTH_LONG).show();
}
catch(Exception e) {
Toast.makeText(MainActivity.this, "沒有回應", Toast.LENGTH_LONG).show();
}
}
} |