Day 8 part 2, the road to getting started with Piggy's Android
This section introduces:
In part 1, we learned the concepts related to xml files used in network interaction and
Parse XML in three different forms: SAX, DOM, and Pull. In part 2, we will
Explains how our applications can obtain resources on the network, including images, HTML code, XML code, and JSON data;
Well, there's so much nonsense. Start this course! Starting from this part, we need to use tomcat to build the server.
Is to create your own web program, you can use eclipse to directly create or download another myeclipse to create a web program
Also, the encapsulated Android IDE provided by the Official Website Cannot create Web programs. Remember!
For beginners who want to read this article:
It turns out that you have learned most about Android. Congratulations! However, I encountered a problem here!
If the network is used, the interaction between the server and the client is inevitable. For Beginners, the more problems are the server.
After all, many of my friends have never touched the server, or the programming of the server! I am also entangled here
I don't know how to explain it for a few days. Since many of my friends have never learned Jsp, Servlet, or other Server programming languages, let alone
The SSH frameworks provide a minimum foundation: you must master the ability to obtain and parse the data from the server,
There is no need to care about the implementation of the server. In fact, many companies have dedicated people responsible for the server! Of course, if
If you have high requirements for yourself, you can also learn simple jsp and servlet by yourself. Of course, you can also learn J2EE or other
Server language!
Due to limited space, this article may not be complete enough. I may not understand some of the content in this article, but please manually repeat it,
I can't understand it, but I can understand it during the process. I don't know how to think twice, so you will get something! Directly paste the following content
You can load the provided web project to tomcat. In addition, you need to change the ip address! Enter cmd in the Start menu and ipconfig
Find the IPV4 IP address!
In addition, we provide some references (if you are interested, you can download them ):
This article reference books: "Android 4.0 network programming": http://pan.baidu.com/s/1o6siI6I
Video: http://pan.baidu.com/s/1jGiN3gE
Ps: After version 4.0, Android network access operations cannot be performed in sub-threads! A new thread is required!
In addition, we recommend using the Vollery framework to access network operations. If you are interested, let's take a look!
This section describes the road map:
Body:
The flowchart of the HTML protocol:
Flowchart analysis:
1) The user enters Baidu's domain name in the browser, clicks access, the domain name is first sent to DNS, the domain name is resolved, get the ip address, and then link to the corresponding server
Port Number (this port is usually used to listen to the client to connect to the server )!
2) The simplest TCP/IP protocol is used from the browser to the port in the service area.
3) There are three types of data returned from the server: HTML, XML, or JSON. In addition, the JavaSE IO technology is used for uploading or downloading files.
Obtain images on the network
:
Code parsing:
Obtain webpage code on the network
:
Ps: Apart from HTML, other php and. net files can be read.
Code parsing:
Parse XML data returned by the server
:
You need to set up the server platform first, and then run tomcat to display the following information:
After accessing this link, the following xml content indicates that the server has been set up!
Then write the client, and the implementation is as follows:
Code parsing:
Parse JSON data returned by the server
:
You need to set up the server platform first, and then run tomcat to display the following information:
After accessing this link, the following xml content indicates that the server has been set up!
Then write the client, and the implementation is as follows:
Code parsing:
Download reference code:
1 get pictures on the Internet: http://pan.baidu.com/s/1eQ1SyA2
② Get Web code on the Internet: http://pan.baidu.com/s/1sjJgYPB
③ Get the xml data returned by the server: http://pan.baidu.com/s/1mgwW4sC
4 get the server returned JSON data: http://pan.baidu.com/s/1pJyms0j
⑤ Web engineering (server): http://pan.baidu.com/s/1hqGb5eW