I want to POST form data using AFNetworking
. I am using this piece of code to achieve this:
// Create service request url
NSString *urlString = [NSString stringWithFormat:@"%@%@", kBaseURL, webServiceAPIName];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"myUser" forHTTPHeaderField:@"X-User-Agent"];
[manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
// Set calling keys
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:@"5341" forKey:@"Id"];
[dict setObject:@"f1" forKey:@"refDataId"];
[dict setObject:@"f1" forKey:@"customRefDataId"];
[dict setObject:@"587" forKey:@"cost"];
[manager POST:urlString parameters:dict constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImagePNGRepresentation(files[0]) name:@"ImageName" fileName:@"file1" mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"upload successful");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error image upload");
}];
After execution of this block after waiting some time it goes in Failure Section. Logging : "Error image upload"
. without giving any error.
I tried my API in POSTMAN API CLIENT
and there it is working fine.I am able to send data and get response back.
And after running this block i am not able to run any other API call I have to stop my app and run again to run any other API call.
What is the issue with this code why I am not able to upload any form data and Why it block my any other API calls