Request method for HTTP

Source: Internet
Author: User


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

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.