B
B
bart12k2019-07-21 17:20:36
Android
bart12k, 2019-07-21 17:20:36

How to send a GET request using OkHttpClient in android?

removed123123123 removed123123123 removed123123123 removed123123123 removed123123123

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
illuzor, 2019-07-22
@iLLuzor

Example from documentation :

OkHttpClient client = new OkHttpClient();

String run(String url) throws IOException {
  Request request = new Request.Builder()
      .url(url)
      .build();

  try (Response response = client.newCall(request).execute()) {
    return response.body().string();
  }
}

S
Sergey Vodakov, 2019-07-22
@WaterSmith

As you have already been answered, you are not fulfilling the request. But, even after you write:
Android will throw an exception that network requests cannot be made on the UI thread.
You need to use at least AsyncTask.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question