引用
#import "Network.h"
按需組合
Network
.url(url)
.params(dict)
.get(^(NSDictionary * result,NSError * error){
NSLog(@"%@",result);
});
- post方法(例子:包含請(qǐng)求頭芥挣、url編碼)
Network
.url(url)
.params(dict)
.headers(headers)
.urlencoded()
.post(^(NSDictionary * result,NSError * error){
NSLog(@"%@",result);
});
- upload方法(例子:包含上傳進(jìn)度攘乒、多個(gè)文件上傳)
NSData * data1 =UIImagePNGRepresentation([UIImage imageNamed:@"xiaohuangren.png"]);
NSData * data2 =UIImagePNGRepresentation([UIImage imageNamed:@"d.jpg"]);
NSDictionary * dict = @{ @"RepairContent":@"上傳圖片測(cè)試22",
@"Files":@[
@{
@"type":@"png",
@"data":data1
},
@{
@"type":@"jpg",
@"data":data2
}
]
};
NSArray * headers =@[@{@"userID":@"3d6f00aa-5a87-41c8-8c02-0042ada0c9d2"}];
Network
.url(@"http://192.168.0.200:8080/api/Base_Attachment/Upload")
.headers(headers)
.params(dict)
.progress(^(float fraction,int64_t completed,int64_t total){
printf("\n進(jìn)度%f 已發(fā)送%lld 總量%lld",fraction,completed,total);
self.progressView.progress = fraction;
})
.upload(^(NSDictionary * result,NSError * error){
NSLog(@"上傳返回結(jié)果:%@",result);
NSLog(@"上傳失敗:%@",error);
});
Network
.url(url)
.params(dict)
.progress(^(float fraction,int64_t completed,int64_t total){
printf("\n進(jìn)度%f 已接收%lld 總量%lld",fraction,completed,total);
self.progressView.progress = fraction;
})
.download(^(NSURL * localUrl,NSError * error){
if (!error) {
printf("\n下載成功!\n");
printf([[localUrl absoluteString] UTF8String],nil);
//NSData * data = [NSData dataWithContentsOfURL:localUrl];
}else{
printf("\n下載失敗!");
}
});
下載地址
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者