iOS-NSURLRequest的理解与应用

来源:互联网 发布:pkpm节能计算软件 编辑:程序博客网 时间:2024/06/03 21:20

NSURLRequest官方文档

@interface NSURLRequest : NSObject <NSSecureCoding, NSCopying, NSMutableCopying>{    @private    NSURLRequestInternal *_internal;}+ (instancetype)requestWithURL:(NSURL *)URL;#if FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST(8)@property (class, readonly) BOOL supportsSecureCoding;#endif+ (instancetype)requestWithURL:(NSURL *)URL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval;- (instancetype)initWithURL:(NSURL *)URL;- (instancetype)initWithURL:(NSURL *)URL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval NS_DESIGNATED_INITIALIZER;@property (nullable, readonly, copy) NSURL *URL;@property (readonly) NSURLRequestCachePolicy cachePolicy;@property (readonly) NSTimeInterval timeoutInterval;@property (nullable, readonly, copy) NSURL *mainDocumentURL;@property (readonly) NSURLRequestNetworkServiceType networkServiceType NS_AVAILABLE(10_7, 4_0);@property (readonly) BOOL allowsCellularAccess  NS_AVAILABLE(10_8, 6_0);@end@interface NSMutableURLRequest : NSURLRequest@property (nullable, copy) NSURL *URL;@property NSURLRequestCachePolicy cachePolicy;@property NSTimeInterval timeoutInterval;@property (nullable, copy) NSURL *mainDocumentURL;@property NSURLRequestNetworkServiceType networkServiceType NS_AVAILABLE(10_7, 4_0);@property BOOL allowsCellularAccess NS_AVAILABLE(10_8, 6_0);@end@interface NSURLRequest (NSHTTPURLRequest) @property (nullable, readonly, copy) NSString *HTTPMethod;@property (nullable, readonly, copy) NSDictionary<NSString *, NSString *> *allHTTPHeaderFields;- (nullable NSString *)valueForHTTPHeaderField:(NSString *)field;@property (nullable, readonly, copy) NSData *HTTPBody;@property (nullable, readonly, retain) NSInputStream *HTTPBodyStream;@property (readonly) BOOL HTTPShouldHandleCookies;@property (readonly) BOOL HTTPShouldUsePipelining NS_AVAILABLE(10_7, 4_0);@end@interface NSMutableURLRequest (NSMutableHTTPURLRequest) @property (copy) NSString *HTTPMethod;@property (nullable, copy) NSDictionary<NSString *, NSString *> *allHTTPHeaderFields;- (void)setValue:(nullable NSString *)value forHTTPHeaderField:(NSString *)field;- (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field;@property (nullable, copy) NSData *HTTPBody;@property (nullable, retain) NSInputStream *HTTPBodyStream;@property BOOL HTTPShouldHandleCookies;@property BOOL HTTPShouldUsePipelining NS_AVAILABLE(10_7, 4_0);@end