IOS network analysis-(four get & amp; post), ios network analysis get

Source: Internet
Author: User

IOS network analysis-(four get & post), ios network analysis get

The default network request is get.

There are many types of network requests: GET query POST change PUT add DELETE HEAD

In normal development, get and post are mainly used.

Get to get data (get user information)

The get request has no length limit. The actual length limit is made by the browser. The length limit is generally 2 k.

Get requests are cached and get algorithms have idempotence.

Get http: // localhost/login. php? Username = xubaoaichiyu & password = 123456

Request Parameters are exposed in the url

Get request parameter format:

? Followed by Request Parameters

Parameter Name = parameter value

& Connect two parameters

Post add and modify data (upload or modify user information)

THE post request is not cached.

Http: // localhost/login. php

There is no length limit for post. Generally, the length is less than 2 MB.

Post request parameters are not exposed and sensitive information is not exposed.

The request header and request body boby (the post parameter is placed in the Request body)

The get code is as follows:

/// ViewController. m // CX-get /// Created by ma c on 16/3/17. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // use the get request to obtain the NSString * String = @" http: // localhost/login. php "; // The splicing parameter NSString * urlString = [NSString stringWithFormat: @" % @? Username = xubaoaichiyu & password = 123456 ", String]; // urlString = [urlString encoding: NSUTF8StringEncoding]; NSURL * url = [NSURL URLWithString: urlString]; NSURLRequest * request = [[NSURLRequest alloc] initWithURL: url cachePolicy: 0 timeoutInterval: 15]; [NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler: ^ (NSURLResponse * _ Nullable response, NSData * _ Nullable data, NSError * _ Nullable connectionError) {NSString * string = [[NSString alloc] initWithData: data encoding: encoding]; NSLog (@ "% @", string) ;}@ end

Post:

/// ViewController. m // CX-post /// Created by ma c on 16/3/17. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // use the post request // obtain the NSString * string = @" http: // localhost/login. php "; // Chinese transcoding string = [string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; NSURL * url = [NSURL URLWithString: string]; // variable request NSMutableURLRequest * requst = [[NSMutableURLRequest alloc] initWithURL: url cachePolicy: 0 timeoutInterval: 15]; // set the transmission mode requst. HTTPMethod = @ "POST"; NSString * bodyString = [NSString stringWithFormat: @ "username = xubaoaichiyu & password = 123456"]; // set the Request body requst. HTTPBody = [bodyString dataUsingEncoding: Unknown]; [NSURLConnection failed: requst queue: [queue mainQueue] completionHandler: ^ (NSURLResponse * _ Nullable response, NSData * _ Nullable data, NSError * _ Nullable connectionError) {NSString * string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; NSLog (@ "% @", string) ;}];}

 

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.