AFNetworking 怎樣上傳數據?
怎樣上傳模擬表單?
求大神代碼提示
和取數據差不多的
首先定義一個字典,用來存放參數
NSDictionary* params = [NSDictionary dictionary];
params[@"屬性"] = 值;
上傳字段數據:
**
//創建請求管理類
AFHTTPRequestOperationManager* mgr = [AFHTTPRequestOperationManager manager];
//發送請求
[mgr POST:url parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
//成功回調
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//失敗回調
}];**
上傳文件數據(事先將文件轉化為二進制data):
//創建請求管理類
AFHTTPRequestOperationManager* mgr = [AFHTTPRequestOperationManager manager];
//發送請求
[mgr POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> totalformData) {
[totalformData appendPartWithFileData:formData.data name:formData.name fileName:formData.fileName mimeType:formData.mimeType];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
//成功回調
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//失敗回調
} ];
**