iOS/Java(GWT+GAE)/UrbanAirship编码德语umlauts

iOS/Java(GWT+GAE)/UrbanAirship编码德语umlauts,java,ios,google-app-engine,gwt,urbanairship.com,Java,Ios,Google App Engine,Gwt,Urbanairship.com,-找到问题的解决方案,代码已更新- 我无法通过推送消息将德语umlautsöäü发送到iPhone。 我在Google AppEngine上运行Java/GWT,并使用UrbanAirship进行推送通知。下面的代码在我的mac上运行得很好,推送通知中包含正确的德国UMLAUT。如果我把它部署到gae服务器上,德国umlauts就不能工作了。到目前为止,我发现GAE上的标准编码是US-ASCII,在这里的帮助下,将getBytes和其他所有内容更改为UTF-8。 问题仍然存在,但现在iPhone

-找到问题的解决方案,代码已更新-

我无法通过推送消息将德语umlautsöäü发送到iPhone。 我在Google AppEngine上运行Java/GWT,并使用UrbanAirship进行推送通知。下面的代码在我的mac上运行得很好,推送通知中包含正确的德国UMLAUT。如果我把它部署到gae服务器上,德国umlauts就不能工作了。到目前为止,我发现GAE上的标准编码是US-ASCII,在这里的帮助下,将getBytes和其他所有内容更改为UTF-8。 问题仍然存在,但现在iPhone上取代umlauts的问号以钻石为背景出现了

我使用的方法是works fine local,而不是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;
}
getBytes没有编码!你应该感到羞耻!嗯,不是真的:

:

使用平台的默认字符集将该字符串编码为字节序列,并将结果存储到新的字节数组中

改用GetByTeString或getBytesCharset-可能与UTF-8一起使用。类似的问题会影响新的Stringbyte[]和其他一些方法


愉快的编码。

谢谢你的回答,可惜没有帮助。我修改了getBytes调用,并使用不同的字符集进行了尝试。如果我使用UTF-8,我得到的是方形背景上的umlauts问号,而不是问号。好的,我更进一步了。我发现应用程序引擎的默认字符集是US-ASCII。我的系统的默认字符集是UTF-8。现在我需要将US-ASCII转换为UTF-8。