0
我在android設備上有httpservice。它對某些瀏覽器形成html頁面的響應。所以它工作正常,但如果我使用其他語言(例如俄語),服務器將返回不可讀的文本,而不是俄語符號。我知道Android上的默認編碼是UTF-8。我已經嘗試了Android上的所有可用編碼(例如windows-1251,Big5(中文),UTF-16等),但它完全返回錯誤結果。下面是一些代碼,告訴你什麼是我試圖做的事:Android沒有合適的編碼
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext httpContext) throws HttpException, IOException {
HttpEntity entity = new EntityTemplate(new ContentProducer() {
public void writeTo(final OutputStream outstream) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(outstream, "windows-1251");
String resp = "<html><body>Hello Привет</body></html>";
StringEntity se = new StringEntity(resp, "windows-1251");
se.writeTo(outstream);
//writer.write(resp);
//writer.flush();
}
});
response.setHeader("Context-Type", "text/html");
response.setEntity(entity);
}
因此,在瀏覽器中我看下:
Hello Привет
什麼我錯了嗎?請回答我。 我會很感激的任何建議。謝謝。
也許服務器不能正確支持utf-8? – Demonick 2012-04-18 05:54:20