What if I had to attach a cookie with a post requst? How should I do this?
NSURL *URL = [NSURL URLWithString:addAddressUrl];
NSMutableURLRequest *request = [NS
Was able to solve it..I have used it with only first way .. may be that can be used in both the ways :
Here is my code of how i was able to upload an image with afnetworking 2.0 :
NSString *fileName = [NSString stringWithFormat:@"Prescription%d.jpg", counter];
NSData *imageData = UIImageJPEGRepresentation(imagePresc, 1.0);
NSString *orderID = [[NSUserDefaults standardUserDefaults] valueForKey:@"orderId"]; // orderId
NSDictionary *parameters = @{@"docName":prescriptionCell.doctorNameTextField.text,@"patientName":prescriptionCell.patientNameTextField.text,@"orderId" : orderID};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"http://staging.healthkartplus.com/webservices/prescription/upload" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData){
[formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
}success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"response is : %@",responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@ *****", [error description]);
}];
The important part of this code is :
[formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
Here in above line of code you need to specify exactly the name of the parameter and the type of the parameter (image). Here the "file" parameter must be passed to it (according to API which i got from my server side guys) and the type should be "image/jpeg"(or image/pdf or i think image/png). and you can pass any name for the fileName, here i am passing file name as : NSString *fileName = [NSString stringWithFormat:@"Prescription%d.jpg", counter];
The only mistake i was doing is i was not specifying correct parameter for image , to summerise i should have sent it like :