N
N
Nikolai Gerasimov2015-03-18 11:03:17
Java
Nikolai Gerasimov, 2015-03-18 11:03:17

How to make a GET request in java/android to get a list of messages?

I rummaged through the Internet, re-read a lot of things, but only got more confused.
In general, there is a task.
For authentication, you must pass a header named Authorization, for example:
Authorization: Bearer 1a1a1a1a1a1a1a1a1a1a1a1a1a1
The API works in JSON format.
Host address: example.ru
1) Getting a list of messages:
Method: GET
URL: /api/mess
Question - how to make a GET request to get a list of messages? If possible, please provide an example.
Does the request need to be executed in an AsyncTask?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikolay Gerasimov, 2015-03-18
@GerNik

I figured it out, I did it using the library from the github, I had to write
Request request = new Request.Builder()
.url(url).addHeader("Authorization","Bearer 1a1a1a1a1a1a1a1a1a1a1a1a1a1")
.build();
and then made a request. All done in AsyncTask

I
IceJOKER, 2015-03-18
@IceJOKER

stackoverflow.com/questions/2938502/sending-post-d...
stackoverflow.com/questions/10287368/adding-author...

O
Oleg Gamega, 2015-03-18
@gadfi

retrofit in your case, when there is little data, you can use callbacks, directly from the main thread)) although if there is a lot of data and they still need to be processed, then it is better to use threads (AsyncTask, AsyncLoader, service ... as you prefer)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question