Network Programming --- HTTP and javahttp Network Programming

Source: Internet
Author: User

Network Programming --- HTTP and javahttp Network Programming

 

URL:

What is URL? The full name of a URL is Uniform Resource Locator (Unified Resource Locator). With one URL, you can find that the only Resource URL on the Internet is the Resource address and location, each resource on the Internet has a unique basic URLURL format = Protocol: // host address/path: Protocol (for example, http) Host address: the IP address (domain name) of the host that stores the resource. (For example, ios.itxz.cn or 202.108.22.5) path: the specific location of the resource in the host. (For example, ios/images/content_1.jpg or img/bdlogo.gif)

 

Common protocols in URLs:

HTTP Hypertext Transfer Protocol accesses remote network resources. The format is http: // http protocol, which is the most common protocol in network development. file accesses resources on local computers, the format is file: // (no host address is needed) mailto accesses the email address. The format is mailto: FTP accesses the file resources of the shared host. The format is ftp ://

 

HTTP protocol Overview

Whether it's a mobile client or a PC, accessing remote network resources often uses HTTP to access the Baidu homepage: http://www.baidu.com get Sina Weibo data get public comments of group buying data HTTP Protocol role HTTP full name is Hypertext Transfer Protocol, hypertext Transfer Protocol specifies the data transmission format between the client and the server so that the client and server can communicate data effectively.

 

HTTP features

Simple and fast because the HTTP protocol is simple, the HTTP server's program size is small, therefore, the communication speed is fast and flexible. HTTP allows the transmission of any type of data. HTTP 0.9 and 1.0 use non-persistent connections to restrict each connection to process only one request. After the server responds to the client request, disconnect immediately. This method can save transmission time.

 

Basic HTTP Communication Process

To use the HTTP protocol to request data from the server, you must first understand the complete HTTP communication process. There are two major requests: the client requests data from the server and the server returns the corresponding data from the client.

 

Scheme for sending HTTP requests in iOS

In iOS, common HTTP request sending solutions include Apple native (built-in) NSURLConnection: simple to use, the oldest, the most classic, and the most direct method. NSURLSession: the New Technology of iOS 7, CFNetwork is more powerful than NSURLConnection: The underlying layer of NSURL *. The third-party framework ASIHttpRequest is pure C language: the nickname "HTTP Terminator", which is extremely powerful. Unfortunately, AFNetworking has been stopped for a long time and is easy to use, provides basic and adequate common functions, maintenance and multi-user MKNetworkKit: simple and easy to use, produced in the hometown of India, Sango. Maintenance and less user suggestions in order to improve development efficiency, enterprise development uses a third-party framework.

 

Comparison between ASI and AFN Architectures

---------------------------------------------------------------------------

----------------------------------------------------------------------------

 

How to send an HTTP request

In the HTTP/1.1 protocol, eight methods for sending http requests are defined: GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, CONNECT, and PATCH. Based on the original design intention of the HTTP protocol, different methods have different operation methods for resources. PUT: Add DELETE: delete post: Change GET: query is the most commonly used GET and POST (in fact, both GET and POST can perform addition, deletion, modification, and query) to use GET and POST requests to interact with the server, you must first understand the specific data transmitted to the server, such as the account and password at login.

 

GET and POST comparison

The main difference between GET and POST is that GET: after the request URL? To keep up with the parameters sent to the server, multiple parameters are separated by &, such as http://ww.test.com/login? Username = 123 & pwd = 234 & type = JSON because the browser and server have restrictions on the URL length, the parameters attached to the URL are limited. Generally, they cannot exceed 1 KBPOST: theoretically, all the parameters sent to the server are placed in the Request body. There is no limit on the amount of data transmitted by POST (depending on the server's processing capability ).

 

GET and POST options

We recommend that you use GET and POST to transmit a large amount of data, such as file upload. The security of POST requests is only less secure than that of POST requests. If it contains confidential and sensitive information, we recommend that you use POST. If you only request data (data query), we recommend that you use GET to add, modify, and delete data. We recommend that you use POST.

 

HTTP Communication Process-Request

HTTP protocol: a complete HTTP request sent from a client to the server contains the following content: contains the request method, request resource path, HTTP Protocol version GET/Server/resources/images/1.jpg HTTP/1.1 request header: host: 192.168.1.105: 8080 // User-Agent: Mozilla/5.0 (Macintosh; intel Mac OS X 10.9) Firefox/30.0 // client type, client software environment Accept: text/html, */* // client can receive data type Accept-Language: zh-cn // The language environment of the client Accept-Encoding: gzip // The Request body in the format of data compression supported by the client: the specific data sent by the client to the server, such as file data

 

Common response status codes

When a client sends a request to the server, the server should respond, that is, return data to the client. The HTTP Protocol stipulates that a complete HTTP response contains the following content status lines: contains the HTTP protocol version, status code, and status English Name HTTP/1.1 200 OK Response Header: contains the description of the Server, the description of the returned data Server: apache-Coyote/1.1 // Type of the Server Content-Type: image/jpeg // Type of returned data Content-Length: 56811 // Length of returned data Date: Mon, 23 Jun 2014 12:54:52 GMT // response time entity content: the specific data that the server returns to the client, such as file data

 

Common response status codes

Related Article

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.