iOS development--network programming OC & Data Request Summary

Source: Internet
Author: User
<span id="Label3"></p><p style="text-align: center;"><p style="text-align: center;"><span style="font-size: 18pt;">Data Request Summary</span></p></p><p><p></p></p><p><p></p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">**************************************get</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Sync</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008000;"><span style="color: #008000;">//first step, Create URL</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #008000;"><span style="color: #008000;">nsurl * url = [[nsurl alloc]initwithstring:@]</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://e.hiphotos.baidu.com/image/w%3D1366%3Bcrop%3D0%2C0%2C1366%2C768/sign= 66f9b9980ef431adbcd2473a7d0097cc/08f790529822720ed8bdbef079cb0a46f21fab4d.jpg</span></span><span style="color: #008000;"><span style="color: #008000;">"];</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008000;"><span style="color: #008000;">//second step, Create request requests via URL</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008000;"><span style="color: #008000;">nsurlrequest * request = [[nsurlrequest Alloc]initwithurl:url cachepolicy: Nsurlrequestreloadignoringlocalcachedata timeoutinterval:15];</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequest Initialization method first Parameter: request Access path, second Parameter: cache protocol, Third Parameter: network request time-out (seconds)</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008000;"><span style="color: #008000;">//where The cache protocol is an enumeration type that contains:</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequestuseprotocolcachepolicy (basic Strategy)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">///nsurlrequestreloadignoringlocalcachedata (ignoring Local cache)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequestreturncachedataelseload (first Use cache, if there is no local cache, download from the original Address)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequestreturncachedatadontload (use Local cache, never download, if there is no cache locally, the request fails, This policy is used for offline Operation)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequestreloadignoringlocalandremotecachedata (ignoring Any caching policies, whether local or remote, always re-downloaded from the original Address)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008000;"><span style="color: #008000;">//nsurlrequestreloadrevalidatingcachedata (if The local cache is valid, do not download, and any other cases are re-downloaded from the original Address)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #008000;"><span style="color: #008000;">//third step, connect to server</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">nsurlresponse * respones = nil;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">nserror * error = nil;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">NSData * reviced = [nsurlconnection sendsynchronousrequest:request returningresponse:&respones error:& error];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//fourth step, convert data into pictures</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">UIImage * image = [[UIImage alloc]initwithdata:reviced];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #008000;"><span style="color: #008000;">_imageview.image = image;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;"></span> to</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Asynchronous</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">*</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//first step, Create URL</span></span><span style="color: #008080;"><span style="color: #008080;"></span> *</span> <span style="color: #008000;"><span style="color: #008000;">nsurl * url = [[nsurl alloc]initwithstring:@]</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://e.hiphotos.baidu.com/image/w%3D1366%3Bcrop%3D0%2C0%2C1366%2C768/sign= 66f9b9980ef431adbcd2473a7d0097cc/08f790529822720ed8bdbef079cb0a46f21fab4d.jpg</span></span><span style="color: #008000;"><span style="color: #008000;">"];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008000;"><span style="color: #008000;">//second step, Create request requests via URL</span></span><span style="color: #008080;"><span style="color: #008080;">Panax Notoginseng</span></span> <span style="color: #008000;"><span style="color: #008000;">nsurlrequest * request = [[nsurlrequest Alloc]initwithurl:url cachepolicy: Nsurlrequestreloadignoringlocalcachedata timeoutinterval:15];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//third step, connect to server</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[nsurlconnection connectionwithrequest:request delegate:self];//(requires proxy method specified in. h)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//receive A response call to the server</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceiveresponse: (nsurlresponse *) response</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">[self.revicedata setlength:0];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008000;"><span style="color: #008000;">}</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008000;"><span style="color: #008000;">//data transfer is always called</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceivedata: (nsdata *) data</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[self.revicedata appenddata:data];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;">Wuyi</span></span> <span style="color: #008000;"><span style="color: #008000;">}</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">///data is not called until it is finished</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">-(void) connectiondidfinishloading: (nsurlconnection *) Connection</span></span><span style="color: #008080;"><span style="color: #008080;"></span> wu</span> <span style="color: #008000;"><span style="color: #008000;">{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">UIImage * image = [[UIImage alloc]initwithdata:self.revicedata];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> about</span> <span style="color: #008000;"><span style="color: #008000;">_imageview.image = image;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">}</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">**************************************post</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Sync</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">*</span></span><span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008000;"><span style="color: #008000;">//first step, Create URL</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">nsurl * url = [[nsurl alloc]initwithstring:@]</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://api.hudong.com/iphonexml.do</span></span><span style="color: #008000;"><span style="color: #008000;">"];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">///second step, Create a mutable requests request via URL (only A variable request is created to set up post Requests)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">nsmutableurlrequest * request1 = [[nsmutableurlrequest Alloc]initwithurl:url cachepolicy: Nsurlrequestreloadignoringcachedata timeoutinterval:100];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;">the <span style="color: #008000;">Maximum time for the//timeoutinterval:post timeout is 240 seconds, and it is useless to set the number of seconds in the Method. </span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> in</span> <span style="color: #008000;"><span style="color: #008000;">//step three, Set the POST request mode</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[request1 sethttpmethod:@ "POST"];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//fourth step, Setting Parameters</span></span><span style="color: #008080;"><span style="color: #008080;"></span> about</span> <span style="color: #008000;"><span style="color: #008000;">NSString * bodystr = @ "type=focus-c";</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">NSData * BODY = [bodystr datausingencoding:nsutf8stringencoding];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[request1 sethttpbody:body];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//fifth step, Connect Server</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">NSData * data = [nsurlconnection sendsynchronousrequest:request1 returningresponse:nil error:nil];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">NSString * str = [[nsstring Alloc]initwithdata:data encoding:nsutf8stringencoding];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", str);</span></span><span style="color: #008080;"><span style="color: #008080;">Bayi</span></span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Asynchronous</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">*</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//first step, Create URL</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">nsurl * url = [[nsurl alloc]initwithstring:@]</span></span><span style="color: #008000; text-decoration: underline;"><span style="color: #008000; text-decoration: underline;">http://api.hudong.com/iphonexml.do</span></span><span style="color: #008000;"><span style="color: #008000;">"];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">///second step, Create a mutable requests request via URL (only A variable request is created to set up post Requests)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">nsmutableurlrequest * request1 = [[nsmutableurlrequest Alloc]initwithurl:url cachepolicy: Nsurlrequestreloadignoringcachedata timeoutinterval:100];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;">the <span style="color: #008000;">Maximum time for the//timeoutinterval:post timeout is 240 seconds, and it is useless to set the number of seconds in the Method. </span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//step three, Set the POST request mode</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[request1 sethttpmethod:@ "POST"];</span></span><span style="color: #008080;"><span style="color: #008080;">94</span></span> <span style="color: #008000;"><span style="color: #008000;">//fourth step, Setting Parameters</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">NSString * bodystr = @ "type=focus-c";</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">NSData * BODY = [bodystr datausingencoding:nsutf8stringencoding];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[request1 sethttpbody:body];</span></span><span style="color: #008080;"><span style="color: #008080;">98</span></span> <span style="color: #008000;"><span style="color: #008000;">//fifth step, Connect Server</span></span><span style="color: #008080;"><span style="color: #008080;"></span> about</span> <span style="color: #008000;"><span style="color: #008000;">[[nsurlconnection alloc]initwithrequest:request2 delegate:self]</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;">101</span></span> <span style="color: #008000;"><span style="color: #008000;">//receive A response call to the server</span></span><span style="color: #008080;"><span style="color: #008080;">102</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceiveresponse: (nsurlresponse *) response</span></span><span style="color: #008080;"><span style="color: #008080;">103</span></span> <span style="color: #008000;"><span style="color: #008000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;">104</span></span> <span style="color: #008000;"><span style="color: #008000;">[self.revicedata setlength:0];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;">106</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">107</span></span> <span style="color: #008000;"><span style="color: #008000;">//data transfer is always called</span></span><span style="color: #008080;"><span style="color: #008080;">108</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceivedata: (nsdata *) data</span></span><span style="color: #008080;"><span style="color: #008080;">109</span></span> <span style="color: #008000;"><span style="color: #008000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[self.revicedata appenddata:data];</span></span><span style="color: #008080;"><span style="color: #008080;">111</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">113</span></span> <span style="color: #008000;"><span style="color: #008000;">///data is not called until it is finished</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">-(void) connectiondidfinishloading: (nsurlconnection *) Connection</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;"> {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">NSString * str = [[nsstring Alloc]initwithdata:self.revicedata encoding:nsutf8stringencoding];</span></span><span style="color: #008080;"><span style="color: #008080;">117</span></span> <span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", str);</span></span><span style="color: #008080;"><span style="color: #008080;">118</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">119</span></span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;">121</span></span> <span style="color: #008080;"><span style="color: #008080;">122</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Delegate Method</span></span><span style="color: #008080;"><span style="color: #008080;">123</span></span> <span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008080;"><span style="color: #008080;">124</span></span> <span style="color: #008000;"><span style="color: #008000;">typically four delegate methods are used:</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008080;"><span style="color: #008080;">126</span></span> <span style="color: #008000;"><span style="color: #008000;">//received to respone, which contains the HTTP request status code and data header information, including data length, encoding format, etc.</span></span><span style="color: #008080;"><span style="color: #008080;">127</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceiveresponse: (nsurlresponse *) response{NSLog (@ "response =%@ ", response); _backdata = [[nsmutabledata alloc]init];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">129</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//when Data is received, the complete data may be split into multiple packages to be sent, each time it is called by the data fragment, so a global NSData object is needed to stitch each piece of data together</span></span><span style="color: #008080;"><span style="color: #008080;">131</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didreceivedata: (nsdata *) data{</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">[_backdata appenddata:data];</span></span><span style="color: #008080;"><span style="color: #008080;">133</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">134</span></span> <span style="color: #008080;"><span style="color: #008080;">135</span></span> <span style="color: #008000;"><span style="color: #008000;">////data Acceptance at the end of the call this method, when the data is the complete data obtained, you can use the data to do after the processing</span></span><span style="color: #008080;"><span style="color: #008080;">136</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connectiondidfinishloading: (nsurlconnection *) connection{</span></span><span style="color: #008080;"><span style="color: #008080;">137</span></span> <span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", [[nsstring alloc]initwithdata:_backdata encoding:nsutf8stringencoding]);</span></span><span style="color: #008080;"><span style="color: #008080;">138</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">139</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> $</span> <span style="color: #008000;"><span style="color: #008000;">//this is a request error is called, error handling cannot be ignored</span></span><span style="color: #008080;"><span style="color: #008080;">141</span></span> <span style="color: #008000;"><span style="color: #008000;">-(void) connection: (nsurlconnection *) connection didfailwitherror: (nserror *) error{</span></span><span style="color: #008080;"><span style="color: #008080;">142</span></span> <span style="color: #008000;"><span style="color: #008000;">if (error.code = = Nsurlerrortimedout) {</span></span><span style="color: #008080;"><span style="color: #008080;">143</span></span> <span style="color: #008000;"><span style="color: #008000;">NSLog (@ "request timed out");</span></span><span style="color: #008080;"><span style="color: #008080;">144</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">145</span></span> <span style="color: #008000;"><span style="color: #008000;">NSLog (@ "%@", [error localizeddescription]);</span></span><span style="color: #008080;"><span style="color: #008080;">146</span></span> <span style="color: #008000;"><span style="color: #008000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">147</span></span> <span style="color: #008080;"><span style="color: #008080;">148</span></span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span></pre><p><p></p></p> <p><p> iOS development--network programming OC & Data Request Summary </p> </p></span>

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.