1
我試圖連接到一個web服務,我的querysting包含一些數據。壞消息是這些數據包含utf-8字符,這會導致問題。android httpclient和utf-8
如果我只是用普通的字符串調用HttpGet,我會得到「非法字符」異常。所以我用google搜索了一下utf-8的魔法。
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
String utfurl = URLEncoder.encode(url, "utf-8");
HttpGet httpGet = new HttpGet(utfurl);
HttpResponse response = httpclient.execute(httpGet);
content = response.getEntity().getContent();
} catch (Exception e) {
Log.d(TAG, "getInputStream: " +e.getMessage());
現在,我不會得到非法字符內,但它似乎惹UPP的utfurl完全因爲我,而不是讓「目標主機不能爲空,或參數設置」。可能是因爲他不認識到「http://」部分是在一個混亂的字符串中。 有什麼建議嗎?
Regards
它是需要包含UTF-8編碼字符(我認爲這很奇怪)的* URL *還是Web服務器返回的內容? – 2011-02-14 07:30:47