iOS新人学習AFNetworking(一)
2202 ワード
:http://download.csdn.net/detail/haogaoming123/8555077
asihttprequest , AFNetworking、 MKNetworkKit. 。 , 。 , 。 , , , :( )
: AFNetworking、UIKit+AFNetworking
#import "AFHTTPRequestOperationManager.h"
#import "AFHTTPSessionManager.h"
AFHTTPRequestOperationManager post , post,
1. :
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];
NSDictionary *parameters =@{@" 1":@"value1",@" 2":@"value2"、、、};
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"1.png"], 1.0);
[manager POST:@" "parameters:parametersconstructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData :imageData name:@"1" fileName:@"1.png" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation,id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"Error: %@", error);
}];
, , [formData appendPartWithFileData :imageDataname:@"1"fileName:@"1.png"mimeType:@"image/jpeg"]
2. post
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManagermanager];
manager.responseSerializer.acceptableContentTypes = [NSSetsetWithObject:@"text/html"];
NSDictionary *parameters = @{@" 1":@"value1",@" 2":@"value2"、、、};
[managerPOST:@" "parameters:parameters
success:^(AFHTTPRequestOperation *operation,id responseObject) {
NSLog(@"Success: %@", responseObject);
}failure:^(AFHTTPRequestOperation *operation,NSError *error) {
NSLog(@"Error: %@", error);
}];