

// 參數(shù):
// 1. FileURL :需要上傳的文件的本地路徑.
// 2. name : 服務(wù)器接收文件參數(shù)的 key 值.
// 3. fileName :上傳文件在服務(wù)器中保存的名稱.
// 4. mimeType :上傳文件的類型.
// 5. error :NULL
[formData appendPartWithFileURL:url name:@"userfile" fileName:@"789" mimeType:@"ooo" error:NULL];
AFNetworking.h '使用AFN框架導(dǎo)入此文件即可'
2》AFNetworkReachabilityManager.h
AFNetworkReachabilityManager.m
"實(shí)時監(jiān)測當(dāng)前網(wǎng)絡(luò)狀態(tài)的管理類",每次網(wǎng)絡(luò)狀態(tài)改變,都會監(jiān)測到;一般使用了這個類,就不再使用'Reachability'這個框架
3》AFSecurityPolicy.h
AFSecurityPolicy.m
"使AFN支持HTTPS的功能",只需要一句代碼
4》AFURLRequestSerialization.h
AFURLRequestSerialization.m
"可以將請求體數(shù)據(jù)格式化為JSON數(shù)據(jù)"。有時候,服務(wù)器需要客戶端傳給他json數(shù)據(jù),此類很少用
5》AFURLResponseSerialization.h
AFURLResponseSerialization.m
"AFN默認(rèn)會自動解析json數(shù)據(jù)",如果后臺傳回的不是json數(shù)據(jù),需要配置解析器類型。解析器類型必須跟服務(wù)器返回的數(shù)據(jù)類型對應(yīng),才能夠成功接收到數(shù)據(jù)
6》AFURLSessionManager.h
AFURLSessionManager.m
"進(jìn)行文件下載"
'步驟'
1.'實(shí)例化AFURLSessionManager
NSURLSessionConfiguration *cgf = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:cgf];
2.'實(shí)例化downloadTask
- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
3.'開啟任務(wù)
[task resume];