Android uses the get method for network value transmission

Two days ago, I learned how to use the get method to transfer values between Android and the web.

Let's talk about the general method today.

Web application

Here, I only build a simple servlet to receive the information sent by Android.

Android client

Here, I want to establish an input box interface for users to input data, and then I submit the data through get. XML interface (two input boxes and one button):

After that, I will transfer the value in the edit box of the interface to the web side in the activity

Main activity (the thread problem here has been discussed earlier):

The newsservice class and the save method in the above code (this class is used to process information and then send it to the web by get). Here I would like to say that the get method we use is to put the data to be transmitted to the web side in the URL path, and then the web side parses it. Therefore, we need to piece up the URL path in the method and then transmit it to the web side (the IP inside is the local IP of my Tomcat server).

If the above information is successfully transmitted to the web (i.e. conn.getresponsecode() = 200), the Android terminal will display "login succeeded", and the information you transmitted will be printed in the form of system.out.println on the console of the web editor.

effect:

Here is just a demonstration of value transfer. There is no need to use the database and input / output stream. These things are indispensable in real development, so we should learn to combine them and apply them.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>