D
D
di_gangsta2016-12-20 18:24:15
Java
di_gangsta, 2016-12-20 18:24:15

How to send and receive server JSON?

Good day! There is a remote server. How to send him a JSON array in Android development? (e.g. when a button is clicked) I know exactly the URL of the server's domain. I tried to implement it like this:
URL url = new URL("here is the URL of the site");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
///////////////////
But something is not working out very well. Experienced developers, please tell a newbie how to work with the server in general? Thank you in advance for your help?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rou1997, 2016-12-20
@di_gangsta

I once wrote a code for sending a simple GET and POST request and I use it, it sends a string, JSON also needs to be sent as a string, here is the code, and do not forget about the flow, on all modern versions of Android it is forbidden to access the network from the UI -stream, you need to create Threador AsyncTask.

O
Oleg Gamega, 2016-12-20
@gadfi

https://square.github.io/retrofit/

I
ivanessence, 2016-12-23
@ivanessence

Perhaps it will suit you, try using websocket technology, it is very convenient to send whatever you want, only you need to raise a web socket server =) here is an example of one of the libraries
https://github.com/TakahikoKawasaki/nv-websocket-client

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question