I want to know the content_type of the NSURLRequest before it is downloaded.
As much as I searched I found the below code as solution :
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *httpRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];
[httpRequest setHTTPMethod:@"HEAD"];
[httpRequest addValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:httpRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPResponse *httpResponse = (NSHTTPResponse*)response;
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary[@"Content_Type"] description]);
}];
[task resume];
But i am always getting the content_type as text/HTML, even if the URL points to an image.
So it might be the content_type of the header which send because of HEAD set at setHTTPMethod:@"HEAD"
.
Please help me to find the actual Content_Type of the NSURLRequest
before downloading it.