Get request and POST request simple description

Source: Internet
Author: User

GET request

1. Set Request path 2     nsstring *urlstr=[nsstring stringwithformat:@ "http://192.168.1.53:8080/mjserver/login?username=%@ &pwd=%@ ", self.username.text,self.pwd.text];3     nsurl *url=[nsurl urlwithstring:urlstr];4     5//    2. Create Request Object 6     nsurlrequest *request=[nsurlrequest requestwithurl:url];7     8//    3. Send Request

POST request
//1. Set Request path 2 Nsurl *url=[nsurl urlwithstring:@ "Http://192.168.1.53:8080/MJServer/login"];//do not need to pass parameters 3 4// 2. Create Request object 5 Nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:url];//default to get request 6 Request.timeoutint erval=5.0;//Set Request Timeout is 5 seconds 7 [email protected] "POST";//Set Request Method 8 9//Set request body NSString *param=[nsstring str ingwithformat:@ "username=%@&pwd=%@", self.username.text,self.pwd.text];11//Convert the stitched string to data, set the request to the body. Httpbody=[param datausingencoding:nsutf8stringencoding];13 14//3. Send Request 

request The header tells the server the type of the client (which can be modified to spoof the server)
1. Set Request path 2     nsurl *url=[nsurl urlwithstring:@ "Http://192.168.1.53:8080/MJServer/login"];//does not need to pass parameters 3      4//    2. Create a Request object 5     Nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:url];//default to get request 6     request.timeoutinterval= 5.0;//Set Request Timeout is 5 seconds 7     [email protected] "POST";//Set Request Method 8      9     //Set request body     NSString *param=[nsstring stringwithformat:@ "username=%@&pwd=%@", self.username.text,self.pwd.text];11     //Convert the stitched string to data, set the request body 12     request. Httpbody=[param datausingencoding:nsutf8stringencoding];13     //client type, can only be written in English     [request setvalue:@ "Ios+android" forhttpheaderfield:@ "user-agent"];

Get and Post differences:

1, get request, the parameters are written directly on the access path. Simple operation, but easy to be seen by the outside, security is not high, address up to 255 bytes;

2, POST request, put the parameters inside the body. Post request operation is relatively complex, need to separate parameters and addresses, but high security, parameters placed inside the body, not easily captured.




Get request and POST request simple description

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.