0
嗨 我想在android中構建一個小休息客戶端。我只是試圖獲得一個可以稍後解析的XML文件。不過,我有一些編碼問題。Android httpclient(請求)編碼問題
ø和å等特殊字符無法識別。 xml文件使用ISO-8859-1編碼,但我無法弄清楚如何強制httpclient使用此編碼。任何人都可以提供幫助?
下面是代碼:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
String URL = "http://konkurrence.rejseplanen.dk/bin/rest.exe";
String result = "";
Button btn;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)findViewById(R.id.tvResponse);
btn = (Button)findViewById(R.id.btnMakeRequest);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String query = "/departureBoard?id=8600626&date=19.03.11&time=07:02&useBus=0";
callWebService(query);
}
});
}
public void callWebService(String q){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL + q);
ResponseHandler<String> handler = new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
tv.setText(result);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
Log.i("test", result);
}
}
在此先感謝。 最好的問候,kenneth