There are other questions with similar names, but none of them helped me. I have to send a request PUTto the server to change the destination status, so I made this method -(void)appointmentStatusChangedTo:(NSString *)statusID atAppointmentID:(NSString *)appointmentIDin which I set the URL and parameters as
NSString *string = [NSString stringWithFormat:@"%@/API/Appointments/3",BaseURLString];
NSDictionary *para = @{
@"AppointmentStatusId":statusID,
@"ID":appointmentID
};
Then I made a url request like
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *req = [[AFJSONRequestSerializer serializer] requestWithMethod:@"PUT" URLString:string parameters:para error:nil];
After that, I set the header for the authorization token as
NSString *token = [NSString stringWithFormat:@"Bearer %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"userToken"]];
[req setValue:token forHTTPHeaderField:@"Authorization"];
So I call it
[[manager dataTaskWithRequest:req completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error){
if (!error) {
if (response) {
NSLog(@"Respose Object: %@",responseObject);
[self.patientsAppointmentsTableView reloadData];
}
}
else {
NSLog(@"Error: %@", error.localizedDescription);
}
}] resume];
Now it successfully sends data to the server, but as an answer I get
Error: The data cannot be read because it is incorrect format.
, , . , . 1. , AFNetworking 3.0 .