我想在我的 Android 应用程序中执行 HTTPRequest,使用以下代码:
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://www.example.de/example.php"));
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
return page;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我正在调用的网页是一个返回字符串的 php 脚本。我的问题是特殊字符(ä、ü、ö、€ 等)显示为带框的问号。我怎样才能得到这些字符?
我认为这是编码的问题(德语应用程序-> UTF-8?)。