From NSHTTPURLResponse documentation, I did not find a way to get the HTTP version (i.e. "HTTP/1.1" or "HTTP/1.0").
HTTP header fields are available through all Header Fields property, however the HTTP protocol version is not given inside the header fields as it is not an HTTP header.
Note: init, NSHTTPURLResponse initializer
(initWithURL:statusCode:HTTPVersion:headerFields:) does require the HTTPVersion as an input, so theoretically it may have been saved there.
However, I couldn't find a property or method to get the HTTPVersion from a given response, for example a response returned from an NSURLSessionDataTask.
There's no public way to access the http version of an
NSHTTPURLResponseinstance, and the version of response is depended on the request version.You can use
CFNetworkingif you really want to access the http version.And the
CFHTTPMessageCopyVersion()returns the HTTP version.Actually the
-[NSHTTPURLResponse initWithURL:(NSURL *)URL statusCode:(NSInteger)statusCode HTTPVersion:(NSString *)version headerFields:(NSDictionary *)fields]usesCFHTTPMessageCreateResponseto create a HTTP response. see NSURLResponse.mThe
NSURLResponseis backed upon the_CFURLResponsestruct.You can get this struct using
_CFURLResponsegetter method on aNSURLResponseinstance: