Get requests and post requests in iOS development

Source: Internet
Author: User

A GET request is typically a network request that does not involve the user's account password, where the GET request is returned to the requested content before the next action can be made.

-(void) requestwithget{

GET Request:

1. Set the request path

NSString * Urlstr = [NSString stringwithformat:@ "http://192.168.1.53:8080/mjserver/login?username=%@&pwd=%@", Self.nametextfield.text,self.pawtextfield.text];

2. Create request object, not set, default to get

Nsurl * url = [Nsurl urlwithstring:urlstr];

3. Sending the request

}

A POST request can be used to send a login request for an account password because its URL does not show the contents of the account and password, so it is relatively secure, and some images are asynchronously downloaded and so on

-(void) requestwithpost{

POST request:

Set Request Path

Nsurl * url = [nsurl urlwithstring:@ "http://192.168.1.53:8080/"];

Create Request Object

Nsmutableurlrequest * request = [nsmutableurlrequest Requestwithurl:url];

Set request Timeout to 5 seconds

request.timeoutinterval=5.0;

Set Request method

[Email protected] "POST";

Set the request body

NSString *param=[nsstring stringwithformat:@ "username=%@&pwd=%@", Self.nameTextField.text, Self.pawTextField.text];

Convert the stitched string to data, set the request body

Request. Httpbody=[param datausingencoding:nsutf8stringencoding];

Send Request

}

Get requests and post requests in iOS development

Related Article

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.