重头戏2:Json请求在本地工作,但在Heroku上不工作

重头戏2:Json请求在本地工作,但在Heroku上不工作,heroku,playframework,Heroku,Playframework,我制作了一个简单的移动(Android)应用程序和网络(Play2.1.0)应用程序。这实际上是一款安卓上的“打鼹鼠”游戏,你可以将你的分数发布在网络应用程序上(当然还可以获得前10名的分数列表) 因此,获取最高分请求和发布请求在本地(在我的计算机上)都能完美地工作。但当我在Heroku上推我的应用程序时,只有在请求工作时才能获得高分。正如我所注意到的,POST请求的问题在于(从Android)接收JSON的web api(Play2)控制器中。我猜它不知道如何从请求中解析Json 我使用这种方

我制作了一个简单的移动(Android)应用程序和网络(Play2.1.0)应用程序。这实际上是一款安卓上的“打鼹鼠”游戏,你可以将你的分数发布在网络应用程序上(当然还可以获得前10名的分数列表)

因此,获取最高分请求和发布请求在本地(在我的计算机上)都能完美地工作。但当我在Heroku上推我的应用程序时,只有在请求工作时才能获得高分。正如我所注意到的,POST请求的问题在于(从Android)接收JSON的web api(Play2)控制器中。我猜它不知道如何从请求中解析Json

我使用这种方式处理Json请求:

我修改了代码以查找问题:

@BodyParser.Of(BodyParser.Json.class)
public static Result newScore() {
    JsonNode json;
    try {
        json = request().body().asJson();
        String jsonString = json.toString();
        return ok(jsonString);
    } catch (Exception e1) {
        return ok("PROBLEM");
    } 
}
localhost上的响应是我发送的json字符串。Heroku上的响应捕获到字符串问题异常。这是一个非常奇怪的问题,我不知道为什么它可以在本地主机上正常工作,但在heroku上却不行。。。有什么想法吗?:)

更新(Android logcat):

02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):错误
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):html,正文,预处理{
02-08 00:01:09.140:I/SendResultService(18709):边距:0;
02-08 00:01:09.140:I/SendResultService(18709):填充:0;
02-08 00:01:09.140:I/SendResultService(18709):字体系列:摩纳哥,“Lucida控制台”,monospace;
02-08 00:01:09.140:I/SendResultService(18709):背景:#ECECEC;
02-08 00:01:09.140:I/SendResultService(18709):}
02-08 00:01:09.140:I/SendResultService(18709):h1{
02-08 00:01:09.140:I/SendResultService(18709):边距:0;
02-08 00:01:09.140:I/SendResultService(18709):背景:#A31012;
02-08 00:01:09.140:I/SendResultService(18709):填充:20px 45px;
02-08 00:01:09.140:I/SendResultService(18709):颜色:#fff;
02-08 00:01:09.140:I/SendResultService(18709):文本阴影:1px 1px 1px rgba(0,0,0,3);
02-08 00:01:09.140:I/SendResultService(18709):边框底部:1px实心#690000;
02-08 00:01:09.140:I/SendResultService(18709):字体大小:28px;
02-08 00:01:09.140:I/SendResultService(18709):}
02-08 00:01:09.140:I/SendResultService(18709):详细信息{
02-08 00:01:09.140:I/SendResultService(18709):边距:0;
02-08 00:01:09.140:I/SendResultService(18709):填充:15px 45px;
02-08 00:01:09.140:I/SendResultService(18709):背景:#F5A0A0;
02-08 00:01:09.140:I/SendResultService(18709):边框顶部:4px实心#D36D6D;
02-08 00:01:09.140:I/SendResultService(18709):颜色:#730000;
02-08 00:01:09.140:I/SendResultService(18709):文本阴影:1px 1px 1px rgba(255255255.3);
02-08 00:01:09.140:I/SendResultService(18709):字体大小:14px;
02-08 00:01:09.140:I/SendResultService(18709):边框底部:1px实心#BA7A7A;
02-08 00:01:09.140:I/SendResultService(18709):}
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):
02-08 00:01:09.140:I/SendResultService(18709):哦,发生了一个错误
02-08 00:01:09.140:I/SendResultService(18709):

02-08 00:01:09.140:I/SendResultService(18709):已使用id6d9a6k11h记录此异常。 02-08 00:01:09.140:I/SendResultService(18709):

02-08 00:01:09.140:I/SendResultService(18709): 02-08 00:01:09.140:I/SendResultService(18709):
解决方案: 好的,我解决了一个问题-事实上这是我的Android代码中的一个问题:

public void postData(String url,JSONObject obj) {
        HttpParams myParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpPost httppost = new HttpPost(url.toString());
            httppost.setHeader("Content-type", "application/json");

            StringEntity se = new StringEntity(obj.toString());
            //se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); // <-- PROBLEM
            httppost.setEntity(se); 

            HttpResponse response = httpclient.execute(httppost);
            String temp = EntityUtils.toString(response.getEntity());
            Log.i(TAG, temp);
        } 
        catch (ClientProtocolException e) {Log.e(TAG, "Client protocol ex");} 
        catch (IOException e) {Log.e(TAG, "io ex");}
    }
public void postData(字符串url,JSONObject obj){
HttpParams myParams=新的BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(myParams,10000);
HttpConnectionParams.setSoTimeout(myParams,10000);
HttpClient HttpClient=新的DefaultHttpClient();
试一试{
HttpPost-HttpPost=newhttppost(url.toString());
setHeader(“内容类型”、“应用程序/json”);
StringEntity se=新的StringEntity(obj.toString());

//se.setContentEncoding(新的BasicHeader(HTTP.CONTENT_TYPE,“application/json”);//您可能想尝试调用
e1.getMessage()
和/或
e1.printStackTrace()
提示导致异常的原因。好的,我用e1.getMessage响应编辑了我的问题。仍然没有线索…我也会粘贴heroku logsOk,我解决了一个问题,但我不能发布,因为这个愚蠢的堆栈溢出不允许我发布。这是我的Android代码中的一个问题。我不应该使用BasicHeader将ContentEncoding设置为我的St所以我注释掉了这一行,它现在可以工作了:se.setContentEncoding(新的BasicHeader(HTTP.CONTENT_TYPE,“application/json”);
public void postData(String url,JSONObject obj) {
        HttpParams myParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpPost httppost = new HttpPost(url.toString());
            httppost.setHeader("Content-type", "application/json");

            StringEntity se = new StringEntity(obj.toString());
            //se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); // <-- PROBLEM
            httppost.setEntity(se); 

            HttpResponse response = httpclient.execute(httppost);
            String temp = EntityUtils.toString(response.getEntity());
            Log.i(TAG, temp);
        } 
        catch (ClientProtocolException e) {Log.e(TAG, "Client protocol ex");} 
        catch (IOException e) {Log.e(TAG, "io ex");}
    }