iOS network programming--day4 (using Nsurlconnection to get data asynchronously)

Source: Internet
Author: User

XCode7 using HTTPS communication, add an attribute @{@ "nsapptransportsecurity" to the Info.plist file: @{@ "nsallowsarbitraryloads": YES}}

Interface website: http://www.webxml.com.cn

XML International Standard

JSON Popular Standard


get: Easy to use, not safe for exposed interfaces

The interface macro definition of QQ online query get
#define Qqonlineurl_get @ "http://webservice.webxml.com.cn/webservices/qqonlinewebservice.asmx/qqcheckonline?qqcode=%@"


(0) #define Macro name @ ""

(1) Write the interface as a macro definition to note the "/http" prefix

(2) The copy behind the host is connected to (1) behind

(3) After the assignment of Get back to (2), change the string to%@ placeholder

(4) Use String to stitch the macro name, wrap the string into an address using nsurl

(5) Use address to obtain Nsurkrequest request

(6) Asynchronously fetching data using nsurlconnection



Post: Use complex, secure, and multi-method

QQ Online query interface macro definition Post
#define Qqonlineurl_post @ "Http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx/qqCheckOnline"


(0) #define Macro name @ ""

(1) write the interface as a macro definition to note the "/http" prefix

(2) The copy behind the host is connected to (1) behind

(3) Copy the back of post to the back of (2)

(4) Get URL

(5) Use Nsmutableurlrequest to get request from URL

(6) Using the Request class method Sethttpmethod set the request mode to post, default to get

(7) Use a string to get the input content, encapsulated into the data type

(8) using the Request class method Sethttpbody set the requestor data

(9) SetValue "value" Forhttpheaderfield "key" to set the request header using the Request class method

For example: [req setvalue:[nsstring stringwithformat:@ "%ld", Paramdata.length] forhttpheaderfield:@ "Content-length"];

(10) Get data asynchronously using Nsurlconnection



iOS network programming--day4 (using Nsurlconnection to get data asynchronously)

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.