当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];