iOS Advanced (Network request)

Source: Internet
Author: User

1. Network Request mode

GET: The URL string url string up to 255 bytes all data transmitted to the server is displayed in the URL, directly visible, unsafe

POST: Large data is converted to binary number security

2. Connection mode

Synchronization connection: Program prone to deadlock phenomenon

Asynchronous connection: Waits for data to be returned (with proxy and block two ways) when creating the Request object, take the Nsmutableurlrequest object and set the request mode and body body

Postblock Asynchronous block

 //Create a Nsurlsession objectNsurlsession *session =[Nsurlsession sharedsession]; //Create a URL objectNsurl *url = [Nsurl urlwithstring:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"]; //Create a requestNsmutableurlrequest *request =[Nsmutableurlrequest Requestwithurl:url]; [Request Sethttpmethod:@"POST"]; [Request sethttpbody:[@"date=20131129&startrecord=1&len=5&udid=1234567890&terminaltype=iphone&cid=213"Datausingencoding:nsutf8stringencoding]]; Nsurlsessiondatatask*task = [Session datataskwithrequest:request completionhandler:^ (NSData *data, Nsurlresponse *response, NSError *error) {        //parsingNsdictionary *dic = [Nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers|nsjsonreadingmutableleaves Error:nil]; NSLog (@"%@", DIC);    }]; [Task resume];

iOS Advanced (Network request)

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.