Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
- Subject: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
- From: Sebastien Boisvert <email@hidden>
- Date: Tue, 17 Oct 2017 22:05:36 +0000 (UTC)
I have the following (simplified) code snippet:
[myURLSession dataTaskWithRequest:request completionHandler:^(NSData *
_Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSUInteger responseCode = httpResponse.statusCode;
(do something based on responseCode value)
....
}] resume];
'request' is a NSURLRequest to an HTTPS server.
I've noticed that most times, the response will come back as a
NSHTTPURLResponse, other times only as a NSURLResponse (which leads to a crash
when I try to get the -statusCode).
I haven't been able to determine why/when NSURLSession will return a
NSHTTPURLResponse vs a NSURLResponse (the requests always go to a HTTP server,
with a http(s):// scheme). I would expect that since the request is sent to a
HTTP server/scheme, it would always return a NSHTTPURLResponse object.
What would make it a NSURLResponse (when a valid response is returned) instead
of a NSHTTPURLResponse?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden