When is a NSURLResponse not a NSHTTPURLResponse?

前端 未结 2 1161
心在旅途
心在旅途 2021-02-12 22:24

I\'ve seen a lot of code, including Apple\'s SimpleURLConnections sample, that simply cast any NSURLResponse to a NSHTTPURLResponse. If it is always a NSHTTPURLResponse why do t

2条回答
  •  猫巷女王i
    2021-02-12 23:00

    It is ok if you are sure that your connection runs via HTTP protocol:

    An NSHTTPURLResponse object represents a response to an HTTP URL load request. It’s a subclass of NSURLResponse that provides methods for accessing information specific to HTTP protocol responses.

    If you are connecting via FTP, for example, then casting NSURLResponse to NSHTTPURLResponse will be incorrect.

提交回复
热议问题