當URLSession:didReceiveChallenge:completionHandler:
方法NSURLSessionDelegate
被調用?當我收到403狀態代碼的回覆時,它是否打電話給我?使用NSURLSession委託授權
如果我在授權後更改第二個請求的請求正文,我可以使用此委託方法進行授權嗎? (我應該改變@"ticket"
)
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];