SocketTimeoutException Retrofit2 @POST请求

时间:2016-10-17 01:33:18

标签: android rest retrofit retrofit2 okhttp3

Retrofit2和SocketTimeoutExceptions是否有任何问题?我可以让@GET个请求生效,但我无法获得@POST个请求。这是Nexus设备的已知问题吗?我无法在任何地方找到解决方案 - 我找到的任何东西,我都试过了。从在清单中设置android:vmSafeMode="true"到在服务器上禁用tcp_timestamp的所有内容;我还将OkHttpClient上的读取,写入和连接超时时间增加到45秒,以查看该工作是否有效 - 但它没有。

有没有人有任何提示?

错误如下所示:

10-16 20:26:00.745 15392-16552/io.havoc.todo D/OkHttp: --> POST http://redacted.amazonaws.com:3000/api/task/create http/1.1
10-16 20:26:00.745 15392-16552/io.havoc.todo D/OkHttp: Content-Type: application/json
10-16 20:26:00.745 15392-16552/io.havoc.todo D/OkHttp: Content-Length: 126
10-16 20:26:00.746 15392-16552/io.havoc.todo D/OkHttp: Accept: application/json
10-16 20:26:00.746 15392-16552/io.havoc.todo D/OkHttp: {"category":"","description":"Y","indexInList":4,"name":"Y","priority":"MEDIUM","user":"57a7bd24-ddf0-5c24-9091-ba331e486dc7"}
10-16 20:26:00.746 15392-16552/io.havoc.todo D/OkHttp: --> END POST (126-byte body)
//After 45 second timeout
10-16 20:26:25.757 15392-16552/io.havoc.todo D/OkHttp: <-- HTTP FAILED: java.net.SocketTimeoutException: timeout
10-16 20:26:25.811 15392-15392/io.havoc.todo E/(NewTaskActivityPresenter.java:49): Socket closed

像这样打电话:

Task newTask = new Task(name, description, "", null, USER, 4, priority, null, null);

        Call<StandardTaskResponse> call = HavocService.getInstance().getHavocAPI().createNewTask(newTask);
        call.enqueue(new Callback<StandardTaskResponse>() {
            @Override
            public void onResponse(Call<StandardTaskResponse> call, Response<StandardTaskResponse> response) {
                LogUtil.v("Response message: " + response.message());
            }

            @Override
            public void onFailure(Call<StandardTaskResponse> call, Throwable t) {
                t.printStackTrace();
            }
        });

0 个答案:

没有答案