尝试在iOS项目

时间:2015-06-01 11:13:42

标签: ios xcode6 afnetworking afnetworking-2

这是我们从示例代码中获取的整个代码并对其进行了修改..

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters1 = @{@"foo": @"bar"};
NSURL *filePath = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/userimage.jpg"]];
NSString  *filePath2 = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/userimage.jpg"];
NSLog(@"this is the filepath: %@", filePath);

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:filePath2]){
  NSLog(@"file exists");
} else {
  NSLog(@"file does not exist");
}

[manager POST:@"http://192.168.0.2/my_project/public_html/test" parameters:parameters1 constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  [formData appendPartWithFileURL:filePath name:@"image" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
  NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  NSLog(@"Error: %@", error);
}];

这是特别的行,当评论时,请求没有超时问题..

constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
  [formData appendPartWithFileURL:filePath name:@"image" error:nil];
}

0 个答案:

没有答案
相关问题