• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
    • Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
      • From: Jens Alfke <email@hidden>
  • Next by Date: Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
  • Next by thread: Re: Why does NSURLSession return NSURLResponse instead of NSHTTPURLResponse
  • Index(es):
    • Date
    • Thread