IOS development network-Summary of network requests (HTTP Protocol) and ios Summary
IOS development network-Summary of network requests (HTTP Protocol)
1. Talk about the HTTP protocol (the complete communication process of the Protocol)
2. Communication Process
1> request
* Client --> Server
* Request content
A. Request Line (Request Method \ HTTP protocol \ request resource path)
B. Request Header (description of client information)
C. Request body (only POST requests are required to store specific data)
2> response
* Server --> Client
* Response content
A. Status line (Response line, Status Code)
B. Response Header (server information, type of returned data, length of returned data)
C. entity content (response body, specific content returned to the client)
3. HTTP Request Method
1> GET
* Parameters are spliced after the URL
* Parameter restrictions
2> POST
* Parameters are in the Request body.
* The parameter is not limited.
4. Methods for sending GET/POST requests in iOS
1> NSURLConnection
* Send a synchronous 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 (asynchronous)
[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];