Wenn URLSession:didReceiveChallenge:completionHandler:
Methode von NSURLSessionDelegate
heißt? Hat es angerufen wenn ich eine Antwort mit 403 Statuscode bekomme?Verwenden NSURLSession Delegat für die Autorisierung
Kann ich diese Delegate-Methode für die Autorisierung verwenden, wenn ich den Anfragetext für die zweite Anfrage nach der Autorisierung ändern soll? (Ich sollte @"ticket"
ändern)
NSURLSession *session = [NSURLSession sharedSession];
NSError *error;
NSDictionary *mapData = @{
@"userIdentity": @{
@"ticket": [SecretStorage sharedInstance].ticket,
@"hotelId": [SecretStorage sharedInstance].hotelId,
@"language": @"ru"
}
};
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"example.com"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.f];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
}];
[dataTask resume];