LYNetwork是完全开源基于get,post请求的网络库
LYNetwork
Basic request Network kit (LYNetwork是完全开源基于get,post请求的网络库)
请高手高抬贵手,不要吐槽。
Install
platform :ios, '7.0' pod 'LYRequest', '~> 0.1'
pod install
Use
- Get
NSURL *url = [NSURL URLWithString:@"http://114.215.101.94:83/service/ads.php?type=1&flag=1"]; LYRequest *request = [LYRequest shareInstance]; [request requestWithURL:url params:nil method:@"get" useCache:NO finishBlock:^(NSData *data) { id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"%@", obj); } errorBlock:^(NSURLConnection *connection, NSError *error) { NSLog(@"error"); }];
- Post
NSURL *url = [NSURL URLWithString:@"http://114.215.101.94:83/service/ads.php"]; NSDictionary *dict = @{@"type":@"1", @"flag":@"1"}; LYRequest *request = [LYRequest shareInstance]; [request requestWithURL:url params:dict method:@"post" useCache:NO finishBlock:^(NSData *data) { id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"%@", obj); } errorBlock:^(NSURLConnection *connection, NSError *error) { NSLog(@"error"); }];
- Download
LYRequest *request = [LYRequest shareInstance]; NSURL *url = [NSURL URLWithString:@"https://d.alipayobjects.com/sec/edit/beta/wkaliedit.dmg"]; [request downloadWithURL:url progressBlock:^(float progress) { self.label.text = [NSString stringWithFormat:@"%d%%",(int)progress]; } finishBlock:^(NSData *data) { NSString *filePath = [[self getDocumentPath] stringByAppendingPathComponent:[url lastPathComponent]]; [data writeToFile:filePath atomically:YES]; } errorBlock:^(NSURLConnection *connection, NSError *error) { NSLog(@"error"); }];
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!