I am trying to make an HTTP PUT request using AFNetworking
to create an attachment in a CouchDB server. The server expects a base64 encoded string in the HTTP b
Here you have an example sending a raw json:
NSDictionary *dict = ...
NSError *error;
NSData *dataFromDict = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingPrettyPrinted
error:&error];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:YOUR_URL parameters:nil error:nil];
req.timeoutInterval = 30;
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[req setValue:IF_NEEDED forHTTPHeaderField:@"Authorization"];
[req setHTTPBody:dataFromDict];
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (!error) {
NSLog(@"%@", responseObject);
} else {
NSLog(@"Error: %@, %@, %@", error, response, responseObject);
}
}] resume];