I’m making an attempt to obtain a picture in Goal C from a CDN that serves photographs. This works fantastic if the picture URL is identical because the URL that was requested. However some photographs will end in a redirect to a special URL (even a special area). For instance, this may be the request URL however then the CDN will redirect to the second URL.
If viewing this in a browser or different context, it really works fantastic (the URL will get up to date, however the picture is proven accurately). However when making an attempt to obtain it utilizing an NSURLSessionDownloadTask, it ends in a 404 standing code.
Right here is the code I’m utilizing to carry out the obtain. The code does work if the picture will not be redirected (the URL of the picture that’s downloaded is identical because the picture URL that was requested). However in any other case, if the server does carry out any redirection, this ends in a 404 standing.
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
configuration.URLCache = nil;
configuration.timeoutIntervalForRequest = 5 * 60;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:key.url];
NSURLSessionDownloadTask *process = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSInteger statusCode = 0;
NSHTTPURLResponse *httpResponse = nil;
if ([response isKindOfClass:NSHTTPURLResponse.class]) {
httpResponse = (NSHTTPURLResponse *)response;
statusCode = httpResponse.statusCode;
} else {
statusCode = error.code;
}
// the standing code is 404 when the server points a redirect
}];
[task resume];
Does anybody know what I might do to get this to work? If I request a picture from URL1 however it’s served again at URL2, then I might simply love to do the obtain anyway. It does not matter if the server redirects to a special URL or not, I might nonetheless prefer to get the picture downloaded.