iOS network programming AFN upload files

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

AFHTTPRequestOperationManager *mgr=[AFHTTPRequestOperationManager manager];

// mgr.responseSerializer = [AFHTTPResponseSerializer serializer];

[mgr POST:@“http://192.168.0.113:8080/WYServer/upload” parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

NSURL *url=[[NSBundle mainBundle] URLForResource:@“4444.jpg” withExtension:nil];

//name is the type of the transferred file

[formData appendPartWithFileURL:url name:@“file” fileName:@“1.jpg” mimeType:@“image/jpg” error:nil];

} success:^(AFHTTPRequestOperation *operation, id responseObject) {

NSLog(@“OK”);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

NSLog(@“error”);

}];

}

Guess you like

Origin blog.csdn.net/m0_67390963/article/details/126722721