【发布时间】:2013-08-07 17:07:10
【问题描述】:
我想在我的 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?)。
【问题讨论】:
-
如果返回正确的字符编码,您能否验证浏览器中的内容。
-
我的浏览器显示内容正确。
-
请通过设置检查,request.setHeader("Content-type", "text/html; charset=utf-8");.
-
做到了,但不起作用...我的浏览器说页面编码为 Cp1252 (Windows-1252)。
标签: java android encoding utf-8 httprequest