How to set a timeout for a JSON request?

Asked

Viewed 80 times

0

I am developing an application in JAVA, Android Studio, and I need to make some JSON requests.

So I created an Asynctask class and do so in theInBackground:

@Override
    protected String doInBackground(String... strings) {
        String command = strings[0];
        String json;
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(command);
        request.addHeader("Authorization", "Basic c3VwZXI6MTIzNA==");
        try {
            HttpResponse response = client.execute(request);
                ...

The problem occurs when the server does not respond, whether it is off or slow even....

How can I do?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.