Error java.net.SocketTimeoutException on Android with REST API

0

I have an application that sends JSON's to a controller so I can handle them and save them to the Database. I have tried and saved them correctly. The problem I have is that I do not get the server's success answer but I have a message the Log

java.net.SocketTimeoutException

I wonder if it is due to the time it lasts the operation will be a lot or if the connection is lost, to make the request use Okhhtps : This is the method I use to send the JSON

OkHttpClient client = new OkHttpClient();
public static final MediaType JSON
        = MediaType.parse("application/json; charset=utf-8");

private void send(String tkn) throws JSONException {
    JSONArray json = getInsertCapturas();

    String url = "http://100.167.100.80/proyecto_sinave_jwt/web/app_dev.php/api/entomologicas";
    RequestBody body = RequestBody.create(JSON, json.toString());
    final okhttp3.Request request = new okhttp3.Request.Builder()
            .url(url)
            .post(body)
            .header("Authorization", "Bearer " + tkn)
            .build();
    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            Log.i("***okhttp**", String.valueOf(e));
        }

        @Override
        public void onResponse(Call call, okhttp3.Response response) throws IOException {
            if (response.isSuccessful()) {

                final String res = response.body().string();
                SubirDatos.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Log.i("***okhttp**", res);
                        tvja.setText(res);
                    }
                });
            }
        }
    });
}

As I mentioned, it takes the JSON and saves it in the base but method onFAilure gets the error

  

java.net.SocketTimeoutException

    
asked by Igmer Rodriguez 28.09.2018 в 18:08
source

0 answers