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)
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 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
Get
1. Set the request path
NSString *urlstr=[nsstring stringwithformat:@ "http://192.168.1.53:8080/mjserver/login?username=%@&pwd=%@", Self.username.text,self.pwd.text];
Nsurl *url=[nsurl URLWITHSTRING:URLSTR];
2. Create a Request object
Nsurlrequest *request=[nsurlrequest Requestwithurl:url];
3. Sending the request
Post
1. Set the request path
Nsurl *url=[nsurl urlwithstring:@ "Http://192.168.1.53:8080/MJServer/login"];//does not need to pass parameters
2. Create a Request object
Nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:url];//default to GET request
request.timeoutinterval=5.0;//Set Request timeout of 5 seconds
[Email protected] "POST";//Set Request method
Set the request body
NSString *param=[nsstring stringwithformat:@ "username=%@&pwd=%@", Self.username.text,self.pwd.text];
Convert the stitched string to data, set the request body
Request. Httpbody=[param datausingencoding:nsutf8stringencoding];
3. Sending the request
Relative to a POST request, all parameters of a GET request are exposed directly to the URL, and the requested URL is typically recorded in the server's access log, and the server's access log is one of the key objects of the hacker attack
User's privacy data such as login password, bank account and so on.
iOS Learning Note 6-get Post method