7.1.1 Android Network Programming and Http Protocol Learning
Category Android Basic Tutorial
Introduction to This Section:
>
Unconsciously, we have finally arrived at the section on Android network programming. What we have been playing with before is all standalone, which is definitely not satisfying, right? Starting from this section, let's learn about some things related to Android network programming: what should Android end network programming do? Learning of the Http protocol, using the built-in Json parsing class to parse Json, several common ways of XML parsing, the use of HttpUrlConnection and HttpClient, file uploading, downloading; the use of WebService, WebView, and the use of Socket communication, etc.!
In addition, we are the client side, and the content of the server side is not within our scope, and Xiaozhu is not good at it. Our minimum requirement is: to be able to master the ability to obtain and parse the data feedback from the server! Well, let's not say much, let's start the content of this section!
1. Three Ways of Interaction between Android and the Internet
2. First Understanding of the Http Protocol
>
In actual development, we usually use communication based on the Http protocol when dealing with the server side, so learning the Http protocol is very important. Of course, we don't need to be too particular about some details, just have a general understanding! They are all some conceptual things!
1) What is the Http Protocol?
>
Answer: hypertext transfer protocol (hypertext transfer protocol), an application layer protocol of the TCP/IP protocol, used to define the process of exchanging data between WEB browsers and WEB servers. After the client connects to the web server, if you want to obtain a certain web resource in the web server, you need to follow a certain communication format. The HTTP protocol is used to define the format of communication between the client and the web server.
2) The Difference between Http 1.0 and Http 1.1
>
Answer: The 1.0 protocol, after the client establishes a connection with the web server, can only obtain a web resource! And the 1.1 protocol allows the client to obtain multiple web resources on a connection after establishing a connection with the web server!
3) The Underlying Workflow of the Http Protocol:
>
Answer: We first need to know two terms:
SYN (synchronous): The handshake signal used when TCP/IP establishes a connection
ACK (Acknowledgement): The acknowledgment character, confirming that the received data has been accepted without error
Then it's the concept of TCP/IP three-way handshake:
The client sends a syn packet (syn = j) to the server, enters the SYN_SEND state, and then waits for the server to confirm
The server receives the syn packet, confirms the client's syn (ack = j + 1), and also sends a SYN packet (syn=k) by itself, that is, a SYN + ACK packet, and the server enters the SYN_RECV state
The client receives the SYN + ACK packet and sends an ACK packet (ack = k +1) to the server. After sending, the client and server enter the ESTABLISHED state, complete the three-way handshake, and then start transmitting data
If it's still not very clear, let's take a look at the schematic diagram of the three-way handshake:
Understood, right? Then let's take a look at the process of an Http operation:
The user clicks on the URL (hyperlink) in the browser, and the Web browser establishes a connection with the Web server
After establishing the connection, the client sends a request to the server, and the format of the request is: Uniform Resource Identifier (URL) + protocol version number (usually 1.1) + MIME information (multiple message headers) + an empty line
After receiving the request, the server provides the corresponding return information, and the return format is: Protocol version number + status line (processing result) + multiple message headers + empty line + entity content (such as the returned HTML)
The client receives the return information from the server, displays it through the browser, and then disconnects from the server; of course, if an error occurs during the process If something goes wrong, the error message will be returned to the client and displayed, such as: the classic 404 error!
If the above process is still not clear, we can use HttpWatch or Firefox to grab the package: PS: The test site is the teaching system of Xiaozhu's school. After entering the account password, request login, and we can see the following information:
Contents included in HTTP request:
2.5.4 AutoCompleteTextView (Autocomplete Text Field) Basic Usage
2.5.8 Notification (Status Bar Notification) Detailed Explanation
3.6 Responding to System Setting Events (Configuration Class)
[4.4.2 Further Exploration of ContentProvider - Document Provider](android-
8.3.4 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part 1)
8.3.5 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part 2)
8.3.6 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part 3)
8.3.7 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part 4)
8.3.8 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part 5)
8.3.14 Several Enums/Constants of Paint and ShadowLayer Shadow Effect
8.3.17 Detailed Explanation of Canvas API (Part 2) - Collection of Clipping Methods
8.3.18 Detailed Explanation of Canvas API (Part 3) - Matrix and drawBitmapMesh
8.4.3 Android Animation Collection - Property Animation - First Glance
8.4.4 Android Animation Collection - Property Animation - Second Glance