AFNetworking ÊÇ iOS Ò»¸öʹÓúܷ½±ãµÄÍøÂ翪·¢¿ò¼Ü¡£½ñÌìÎÒÃǾͼòµ¥½éÉÜÈçºÎÔÚÎÒÃǵÄÏîÄ¿ÖÐʹÓÃËü¡£
1¡¢´Ó¹ÙÍøÏÂÔØ×îеÄAFNetworking´úÂë¡£
2¡¢½«AFNetWorkingºÍUIKit+AFNetworkingÎļþ¼Ðµ¼ÈëÏîÄ¿
3¡¢Ìí¼ÓÀà¿â Security.framework¡¢MobileCoreServices.framework¡¢SystemConfiguration.framework
4¡¢ÔÚʹÓõĵط½µ¼Èë
#import AFNetworking.h
#import UIKit+AFNetworking.h
5¡¢ÍøÂçurl·ÃÎʲâÊÔ¡£
NSString *URLTmp = @http://www.coneboy.com;
?
NSString *URLTmp1 = [URLTmp stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//תÂë³ÉUTF-8 ·ñÔò¿ÉÄÜ»á³öÏÖ´íÎó
URLTmp = URLTmp1;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: URLTmp]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@Success: %@, operation.responseString);
NSString *requestTmp = [NSString stringWithString:operation.responseString];
NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];
//ϵͳ×Ô´øJSON½âÎö
NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];
NSLog(@success:%@,resultDic);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@Failure: %@, error);
//[SVProgressHUD dismissWithError:@Ìύʧ°Ü£¬ÇëÖØÊÔ];
}];
[operation start];
6¡¢ÈçºÎ»ñȡһÕÅÍøÂçͼƬ
?
NSString *url = @https://www.cppentry.com/upload_files/article/45/1_y20gh__.jpg;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 150.0f, 200.0f, 200.0f)];
[imageView setImageWithURL:[NSURL URLWithString:url]];
[self.view addSubview:imageView];
?