Answer the question
In order to leave comments, you need to log in
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
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 Thread
or AsyncTask
.
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 questionAsk a Question
731 491 924 answers to any question