"Android Development advanced from small to expert" Reading notes--http network request

Source: Internet
Author: User

NO1:

Client-to-server interaction flow:

1) The client executes the network request and resolves the server hostname from the URL

2) Convert the host name of the server to the IP address of the server

3) Parse the port number from the URL

4) Establish a TCP connection from the client to the Web server

5) The client sends an HTTP request through the output flow to the server

6) The server sends an HTTP response message back to the client

7) The client obtains the message from the input stream

8) Client parsing message, closing connection

9) The client displays the results on the UI

No2:

HTTP request mode:

1) GET

Get a resource in the server, www.devtf.cn/articles/123.html?username=myname&userid=123

2) POST

A form that will typically be used to submit HTML

3) PUT

A resource is written to the server

4) DELETE

Requests that the server delete the resource specified by the request URL. However, the client application cannot guarantee that the delete operation will be performed. Because the HTTP specification allows the server to revoke a request without notifying the client. The Delete method is the same as the GET request, and the parameters need to be placed in the requested URL.

5) HEAD

Similar to the Get method behavior, but the server returns only the header in the response and does not return the body part of the entity. This allows the client to check the header of the resource without acquiring the actual resources.

6) TRACE

A trace request initiates a "loopback" diagnostic on the destination server. The server at the last stop of the trip bounces back a trace response and carries the original request message it received in the response body. This allows the client to see whether and how the original message was destroyed or modified on the request/response chain consisting of all intermediate HTTP applications.

Used primarily for diagnostics, that is, to verify that the request crossed the request/response chain

7) Options Request

The options method requests the Web server to inform it of the various features it supports. You can ask what methods the server typically supports, or which methods are supported for certain special resources (some servers may only support specific actions for some special types of objects)

No3:

An HTTP request message consists of a request line, a request header (header), a blank line, and 4 parts of the requested data.

The HTTP response is also made up of 3 parts: The status line, the message header, and the response body.

No4:

Common status codes, status descriptions

1) OK: Client request succeeded

2) Request: Client requests have syntax errors and cannot be understood by the server

3) 401 Unauthorized: Request unauthorized, this status code must be used with the Www-authenticate header domain

4) 403 Forbidden: The server receives the request but refuses to provide the service

5) 404 Not Fount: The request resource does not exist, for example: The wrong URL was entered

6) Internal Server error: Unexpected errors on server

7) 503 Server Unavailable: The server is currently unable to process client requests and may return to normal after a period of time, for example: http/1.1 OK (CRLF)

NO5:

When HTTP transmits a message, the contents of the message data are transmitted sequentially through an open TCP connection in the form of a stream. After TCP receives the data stream, it splits the data stream into small chunks of data called segments and encapsulates the segments in IP packets for transmission over the Internet. All of this work is handled by TCP/IP software, and programmers can't see anything.

NO6:

There are two ways to perform network requests in Android, one is to use Apache's httpclient, and the other is Java's httpurlconnection.

No7:

HttpURLConnection API is simple, small size, its compression and caching mechanism can effectively reduce network access to traffic, in the speed and power saving also played a big role.

In Android 6.0, the HttpClient library has been removed.

No8:

Once a parameter is written to the output stream, the request becomes post, even though the request is set to "GET" through the Setrequestmethod function. Because the GET request parameter is appended to the URL, do not set the parameter in the request body if it is a GET request.

"Android Development advanced from small to expert" reading notes--design and implementation of network framework

"Android Development advanced from small to expert" Reading notes--http network request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.