1.GET
1> Features
* All request parameters are stitched behind the URL
2> Disadvantages
* All request data is exposed in the URL, not too secure
* URL is limited in length and cannot send too many parameters
3> Use occasions
* If you only request data from the server, you typically use GET requests
4> How to send a GET request
* Default is GET request
1.URL
Nsurl *url = [Nsurl urlwithstring:@ "http://www.baidu.com"];
2. Request
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
3. Sending the request
[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {
}];
2.POST
1> Features
* Place all request parameters in the request body (httpbody)
* Theoretically, there is no limit to the size of the data sent to the server
2> Use occasions
* In addition to requesting data from the server, you can use the POST request
* If the data sent to the server is some privacy, sensitive data, you must use the POST request
3> How to send a POST request
1. Create a URL: request path
Nsurl *url = [Nsurl urlwithstring:@ "Http://localhost:8080/MJServer/login"];
2. Create a request
Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url];
Set Request method
Request. HttpMethod = @ "POST";
Set Request body: Request parameters
NSString *param = [NSString stringwithformat:@ "username=%@&pwd=%@", Usernametext, Pwdtext];
NSString-NSData
Request. Httpbody = [param datausingencoding:nsutf8stringencoding];
Request method for HTTP