// 异步请求
// 1.创建请求
// 请求地址
NSString *str =@"网络请求的图片地址";
// 对字符串进行编码,将汉字等特殊字符转为 UTF-8格式
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// 把字符串转换成 url 格式
NSURL *url = [NSURLURLWithString:str];
// 网络请求,
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL:url];
// 设置网络请求格式,默认是 get 请求
request.HTTPMethod =@"GET";
// 2.发送请求(异步链接服务器)
// 发送请求有两种方式:同步,异步
// 异步的方式比较好
// 同步,异步请求
// 参数1:创建好的请求
// 参数2:操作队列,多线程里面的东西,请求完成在那个队列执行代码(UI界面的刷新和视图赋值都要在主队列执行)
// 参数3:错误信息
[NSURLConnectionsendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response,NSData *data, NSError *connectionError) {
// 3.在 block 里面处理数据
UIImage *image = [UIImageimageWithData:data];
self.imageView.image = image;
}];