HTTP common requests, get and post
One, get and post
GET and POST are the two most common HTTP methods for interacting with the server
1.GET
The semantics of Get is the resource that gets the specified URL
Add the data in the form of Variable=value , followed by the URL to which the action points, and both use "?" Connection, using "&" connection between variables
seemingly unsafe because the data is placed in the requested URL during the transfer
The amount of data transferred is small, mainly because of the URL length limit
2.POST
The semantics of post is to add data to the resource of the specified URL
Place the data in the data body and pass it to the URL that the action points to, in the same way that the variable and the value correspond
All data is not visible to users
Can transfer a lot of data, upload files can only use post
Related to user privacy, be sure to use post, such as user login, bank card Account
Two, GET request example
Three, POST request example
Four Judging get&post requests in the browser
1. Because the POST request sends the data body to the server, a prompt window appears when the page is refreshed
2. The GET request does not send the data body to the server, so there is no prompt
3. from the nature of the request, get requests are more secure and more efficient than post requests
Five Easily view the contents of a POST request with Firebug
In the development of network applications, the browser tracking the return of the URL is an important means of development
Six To send network requests to the iOS network
1. Instantiate URLs( network resources )
2, based on the URL to establish urlrequest( network request )
-Default to GET request
-For a POST request, the requested data body needs to be created
3. Send network requests using URLConnection ( establish connection )
4. Get Results
Nsurlconnection provides two static methods to send network requests directly to the server in a synchronous or asynchronous manner
Sync Request:
sendsynchronous Request:returningResponse:error:
Asynchronous Request:
sendasynchronous Request:queue:completionHandler:
Seven Binary data stream of network transmission
In the process of network request, the process of receiving data is actually implemented by NsurlconnectionDatadelegate , and the common proxy methods include:
The server begins to return data, ready to work
-(void) Connection:didreceiveresponse:
When the data returned by the server is received , This method is called multiple times
-(void) Connection:didreceivedata:
Data received, the final processing of data
-(void) Connectiondidfinishloading:
Network connection Error
-(void) Connection:didfailwitherror:
Let Nsurlconnectiondatadelegate execute asynchronously
[Connection Setdelegatequeue:[[nsoperationqueue alloc] init]];
Ios_ Network _02_get&post