iOS Development Network Chapter-HTTP Protocol

Source: Internet
Author: User
Tags apache tomcat

Description: Apache Tomcat server must occupy port 8080

First, the URL

1. Basic Introduction

The full name of the URL is uniform Resource Locator (Uniform Resource Locator)

With 1 URLs, you can find the only 1 resources on the Internet

URLs are the addresses and locations of resources, and each resource on the Internet has a unique URL

Common protocols in 2.URL

(1) HTTP

Hypertext Transfer Protocol, access to remote network resources, the format is HTTP//

HTTP protocol is the most commonly used protocol in network development.

(2) file

Access to resources on the local computer in the format file://(no host address)

(3) Mailto

The email address is accessed in the format mailto:

(4) FTP

The file resource for the shared host is accessed in the format ftp://

Second, the HTTP protocol

Introduction to the 1.HTTP protocol

Access remote network resources, both mobile and PC, often using the HTTP protocol

Visit Baidu homepage:http://www.baidu.com

Get Sina Weibo data

Get mass reviews of group buy data

The role of the 2.HTTP protocol

The full name of HTTP is Hypertext Transfer Protocol, Hypertext Transfer Protocol

(1) Specify the data transfer format between the client and the server

(2) To enable the client and the server to effectively communicate data

3. Why do I choose to use HTTP?

(1) Simple and fast because the HTTP protocol is simple, so the HTTP server program size is small, so communication speed quickly

(2) Flexible HTTP allows the transfer of any type of data

(3) HTTP 0.9 and 1.0 use a non-persistent connection to restrict each connection to only one request, and the server will disconnect immediately after responding to the client's request, which can save transfer time

The 4.HTTP communication process

To use the HTTP protocol to request data from the server, you need to understand the complete process of HTTP communication first

Complete HTTP communication can be divided into 2 major steps

(1) request: Client asks for data from server

(2) response: The server returns the corresponding data for the client

Iii. HTTP Communication Process-Request and response

1.HTTP Communication Process-Request

The HTTP protocol stipulates that a complete HTTP request sent by the client to the server contains the following content

Request Line: Contains the request method, the request resource path, the HTTP protocol version

Get/mjserver/resources/images/1.jpg http/1.1

Request Header: Contains information about the client's environment description, the host address requested by the client, and so on

host:192.168.1.105:8080 //The server host address that the client wants to access

user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10.9) firefox/30.0//client type, client software environment

accept:text/html, thetype of data that the */*//client can receive

ACCEPT-LANGUAGE:ZH-CN //Client language environment

Accept-encoding:gzip //client-supported data compression formats

Request body: Specific data that the client sends to the server, such as file data

2.HTTP Communication Process-response

The client sends a request to the server and the server should respond by returning the data to the client

The HTTP protocol specifies that a complete HTTP response contains the following:

Status line: Contains the HTTP protocol version, status code, status English name

http/1.1 OK

Response header: Contains a description of the server, a description of the returned data

server:apache-coyote/1.1 //type of server

Content-type:image/jpeg //type of return data

content-length:56811 //length of returned data

Date:mon, June 12:54:52 GMT //Response time

Entity content: Specific data that the server returns to the client, such as file data

3. Supplement: Recommended Tool FIREBUG-1.12.5-FX.XPI

The role of the worm: intercept all HTTP requests.

4. Common response Status Codes

Iv. ways to send HTTP requests

1. Brief description

In the http/1.1 protocol, 8 ways to send HTTP requests are defined

GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, CONNECT, PATCH

According to the original design of the HTTP protocol, different methods have different ways to operate the resources.

PUT: Increase

Delete: Delete

POST: Change

GET: Check

Tip: The most common is get and post (actually get and post can be added and deleted)

2.get and POST requests

To use get and post requests to interact with the server, you need to understand a concept: parameters are the specific data that is passed to the server, such as the account number at login, password

Get vs. Post comparison: The main difference between get and post is on data passing

GET

After the request URL in the form of "to follow the parameters issued to the server, a number of parameters separated by &, such as Http://ww.test.com/login?username=123&pwd=234&type=JSON

Note: Because the browser and server have a limited URL length, the parameters that are included with the URL are limited and usually cannot exceed 1KB

POST

All parameters sent to the server are placed in the request body

In theory, there is no limit to the amount of data that can be transmitted by post (depending on the processing power of the server)

Selection of 3.GET and post

Select the Get and post recommendations

(1) If you want to pass a large amount of data, such as file upload, can only use POST request

(2) Get security is worse than post, if it contains confidential \ Sensitive information, it is recommended to use post

(3) If you only request data (data query), it is recommended to use get

(4) If you are adding, modifying or deleting data, it is recommended to use post

Scenarios for sending HTTP requests in 4.iOS

In iOS, the common solution for sending HTTP requests (get and post) is

(1) Apple native (comes with)

Nsurlconnection: Simple to use, the oldest and most direct of a program

Nsurlsession:ios 7 new technology, features more powerful than nsurlconnection

Cfnetwork:nsurl* 's bottom, pure C language

(2) Third party framework

ASIHTTPRequest: Nickname "http Terminator", the function is extremely powerful, unfortunately has already stopped the update

Afnetworking: Simple and easy to use, providing a basic enough common function

Suggestions:

In order to improve development efficiency, enterprise development is basically a third-party framework

5.ASI and AFN Architecture comparison

Description: AFN based on Nsurl,asi Cfhttp,asi-based performance is better.

iOS Development Network Chapter-HTTP Protocol

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.