iOS開發(fā)常用的第三方類庫
4
5
6
7
8
9
10
11
12
13
NSURL *url = [NSURL URLWithString:@ http://allseeing-i.com ];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
它的ASIFormDataRequest子類可以橫容易的提交表單數(shù)據(jù)和文件:
本文引用地址:http://2s4d.com/article/201610/305920.htm1 2 3 4 5 6 7 8 | ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request setPostValue:@Ben forKey:@first_name]; [request setPostValue:@Copsey forKey:@last_name]; // Upload a file on disk [request setFile:@/Users/ben/Desktop/ben.jpg withFileName:@myphoto.jpg andContentType:@image/jpeg forKey:@photo]; // Upload an NSData instance [request setData:imageData withFileName:@myphoto.jpg andContentType:@image/jpeg forKey:@photo]; |
評論