IOS network programming-Day4 (using NSURLConnection to obtain data asynchronously)

Source: Internet
Author: User

IOS network programming-Day4 (using NSURLConnection to obtain data asynchronously)
XCode7 uses HTTPS communication, in info. add an attribute @ {@ "NSAppTransportSecurity" in the plist file: @ {@ "NSAllowsArbitraryLoads": YES} xml International Standard json popular standard get: easy to use, interface exposed unsafe // QQ online query interface macro definition GET # define QQOnlineURL_GET @ "http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx/qqCheckOnline? QqCode = % @ "(0) # define macro name @" "(1) when writing an interface into a macro definition, add the prefix" http: // "(2) copy and splice the values after the Host to the end of (1) (3) and splice the values after GET to the end of (2). Change the string to % @ placeholder (4) and splice the macro name with the string, encapsulate the string into an address using NSURL (5) use the address to obtain the NSURKRequest request (6) Use NSURLConnection to obtain data asynchronously post: complex and secure, method of Multi // QQ online query interface macro definition POST # define QQOnlineURL_POST @ "http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx/qqCheckOnline" (0) # define macro name @ "" (1) the interface written macro definition to pay attention to add "http: // "prefix (2) concatenate copies after the Host to the end of (1) (3) splice copies after the POST to the end of (2) (4) Get url (5) use NSMutableURLRequest to obtain the request according to the url (6) use the request class method setHTTPMethod to set the request Method to POST, the default is GET (7) use the string to GET the input content, encapsulated into the data type (8) use the request class method setHTTPBody to set the request body data (9) use the request class method setValue "value" forHTTPHeaderField "key" to set the request header, for example, [req setValue: [NSString stringWithFormat: @ "% ld", paramData. length] forHTTPHeaderField: @ "Content-Length"]; (10) obtain data asynchronously using NSURLConnection

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.