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