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 protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com
This email sent to [email protected]