--找到了我的问题的解决方案,代码更新了--
我在通过推送消息向 iPhone 发送德语变音符号 (öäü) 时遇到问题。我在 Google AppEngine 上运行 Java/GWT 并使用 UrbanAirship 进行推送通知。以下代码在我的 Mac 上完美运行,推送通知带有正确的德语变音符号。如果我将它部署到 gae 服务器,德国变音符号不起作用。到目前为止,我发现在 GAE 上,标准编码是 US-ASCII 并且在此处的一些帮助下将 getBytes() 和其他所有内容更改为 UTF-8。问题仍然存在,但现在用“钻石”作为背景来代替 iPhone 上的变音符号的问号?!
这是我正在使用的方法(在本地工作正常,而不是在 GAE):
private Boolean sendNotification(String appKey, String appMasterSecret, String jsonBodyString) {
try {
URL url = new URL("https://go.urbanairship.com/api/push/broadcast/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setConnectTimeout(12000);
String authString = appKey + ":" + appMasterSecret;
String authStringBase64 = Base64.encode(authString.getBytes("UTF-8"));
authStringBase64 = authStringBase64.trim();
connection.setRequestProperty("Content-type", "application/json; charset:utf-8");
connection.setRequestProperty("Authorization", "Basic " + authStringBase64);
OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
osw.write(new String(jsonBodyString.getBytes("UTF-8"),"UTF-8"));
osw.close();
int responseCode = connection.getResponseCode();
String responseMessage = connection.getResponseMessage();
if (responseCode == 200)
return true;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return false;
}