iOS Development Web Chapter-Network request (HTTP protocol) summary

Source: Internet
Author: User

iOS Development Web Chapter-Network request (HTTP protocol) summary

1. Talk about the HTTP protocol (the complete communication process for the Protocol)

2. Communication process

1> Request

* Client-to-server

* Content of the request

A. Request line (Request method \http protocol \ Request Resource Path)

B. Request header (information describing the client)

C. Request body (POST request only needs to have, store specific data)

2> response

* Server-to-client

* Content of the response

A. Status line (response line, status code)

B. Response header (server information, type of return data, length of returned data)

C. Entity content (response body, specific content returned to the client)

3.HTTP method of Request

1> GET

* Parameters are stitched behind the URL

* Parameters are Limited

2> POST

* Parameters are in the request body

* No restrictions on parameters

The means of sending get\post requests in 4.iOS

1> nsurlconnection

* Send a sync request

+ (NSData *) Sendsynchronousrequest: (nsurlrequest *) Request Returningresponse: (Nsurlresponse *) Response error: ( Nserror * *) error;

* Send an asynchronous request

+ (void) Sendasynchronousrequest: (nsurlrequest*) Request

Queue: (nsoperationqueue*) queue

Completionhandler: (void (^) (nsurlresponse* response, nsdata* data, nserror* connectionerror)) handler;

* Proxy method (async)

[Nsurlconnection connectionwithrequest:request delegate:self];

[[Nsurlconnection alloc] initwithrequest:request delegate:self];

[[Nsurlconnection alloc] initwithrequest:request delegate:self Startimmediately:yes];

Nsurlconnection *conn = [[Nsurlconnection alloc] initwithrequest:request delegate:self Startimmediately:no];

[conn start];

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.