+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;
+ (void)sendAsynchronousRequest:(NSURLRequest*) request queue:(NSOperationQueue*) queue completionHandler:(void (^)(NSURLResponse* response, NSData* data, NSError* connectionError)) handler NS_AVAILABLE(10_7, 5_0);
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate;
可以在delegate类里面的下列代理函数,获取异步请求的返回的数据与结果
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connectionDidFinishLoading:(NSURLConnection *)connection - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
除了NSURLConnection之外,还有第三方的网络组件,比如ASIHTTPRequest跟AFNetworking,都是大家用得比较多的。这些第三方的网络组件封装了一些常用功能,满足基本需求,同时也做了更多的扩展,可以处理更加复杂的需求。
想实现更复杂的功能,甚至可以直接用socket,因为socket才是最底层的