Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/Foundation.framework |
Availability | Available in Mac OS X v10.2 with Safari 1.0 installed. Available in Mac OS X v10.2.7 and later. |
Companion guide | |
Declared in | NSURLRequest.h |
Related sample code |
NSURLRequest
objects represent a URL load request in a manner independent of protocol and URL scheme.
NSURLRequest encapsulates two basic data elements of a load request: the URL to load, and the policy to use when consulting the URL content cache made available by the implementation.
NSURLRequest is designed to be extended to support additional protocols by adding categories that access protocol specific values from a property object using NSURLProtocol’s propertyForKey:inRequest:
and setProperty:forKey:inRequest:
methods.
The mutable subclass of NSURLRequest is NSMutableURLRequest.
+ requestWithURL:
– initWithURL:
+ requestWithURL:cachePolicy:timeoutInterval:
– initWithURL:cachePolicy:timeoutInterval:
– allHTTPHeaderFields
– HTTPBody
– HTTPBodyStream
– HTTPMethod
– HTTPShouldHandleCookies
– valueForHTTPHeaderField:
Creates and returns a URL request for a specified URL with default cache policy and timeout value.
+ (id)requestWithURL:(NSURL *)theURL
The URL for the new request.
The newly created URL request.
The default cache policy is NSURLRequestUseProtocolCachePolicy
and the default timeout interval is 60 seconds.
NSURLRequest.h
Creates and returns an initialized URL request with specified values.
+ (id)requestWithURL:(NSURL *)theURL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval
The URL for the new request.
The cache policy for the new request.
The timeout interval for the new request, in seconds.
The newly created URL request.
NSURLRequest.h
Returns a dictionary containing all the receiver’s HTTP header fields.
- (NSDictionary *)allHTTPHeaderFields
A dictionary containing all the receiver’s HTTP header fields.
NSURLRequest.h
Returns the receiver’s cache policy.
- (NSURLRequestCachePolicy)cachePolicy
The receiver’s cache policy.
NSURLRequest.h
Returns the receiver’s HTTP body data.
- (NSData *)HTTPBody
The receiver's HTTP body data.
This data is sent as the message body of a request, as in an HTTP POST
request.
NSURLRequest.h
Returns the receiver’s HTTP body stream.
- (NSInputStream *)HTTPBodyStream
The receiver’s HTTP body stream, or nil
if it has not been set. The returned stream is for examination only, it is not safe to manipulate the stream in any way.
The receiver will have either an HTTP body or an HTTP body stream, only one may be set for a request. A HTTP body stream is preserved when copying an NSURLRequest object, but is lost when a request is archived using the NSCoding protocol.
NSURLRequest.h
Returns the receiver’s HTTP request method.
- (NSString *)HTTPMethod
The receiver’s HTTP request method.
The default HTTP method is “GET”.
NSURLRequest.h
Returns whether the default cookie handling will be used for this request.
- (BOOL)HTTPShouldHandleCookies
YES
if the default cookie handling will be used for this request, NO
otherwise.
The default is YES
.
In Mac OS X v10.2 with Safari 1.0 the value set by this method is not respected by the framework.
NSURLRequest.h
Returns a URL request for a specified URL with default cache policy and timeout value.
- (id)initWithURL:(NSURL *)theURL
The URL for the request.
The initialized URL request.
The default cache policy is NSURLRequestUseProtocolCachePolicy
and the default timeout interval is 60 seconds.
NSURLRequest.h
Returns an initialized URL request with specified values.
- (id)initWithURL:(NSURL *)theURL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval
The URL for the request.
The cache policy for the request.
The timeout interval for the request, in seconds.
The initialized URL request.
This is the designated initializer for NSURLRequest
.
NSURLRequest.h
Returns the main document URL associated with the request.
- (NSURL *)mainDocumentURL
The main document URL associated with the request.
This URL is used for the cookie “same domain as main document” policy.
NSURLRequest.h
Returns the receiver’s timeout interval, in seconds.
- (NSTimeInterval)timeoutInterval
The receiver's timeout interval, in seconds.
If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out.
NSURLRequest.h
Returns the request's URL.
- (NSURL *)URL
The request's URL.
NSURLRequest.h
Returns the value of the specified HTTP header field.
- (NSString *)valueForHTTPHeaderField:(NSString *)field
The name of the header field whose value is to be returned. In keeping with the HTTP RFC, HTTP header field names are case-insensitive.
The value associated with the header field field, or nil
if there is no corresponding header field.
NSURLRequest.h
These constants are used to specify interaction with the cached responses.
enum { NSURLRequestUseProtocolCachePolicy = 0, NSURLRequestReloadIgnoringLocalCacheData = 1, NSURLRequestReloadIgnoringLocalAndRemoteCacheData =4, NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData, NSURLRequestReturnCacheDataElseLoad = 2, NSURLRequestReturnCacheDataDontLoad = 3, NSURLRequestReloadRevalidatingCacheData = 5 }; typedef NSUInteger NSURLRequestCachePolicy;
NSURLRequestUseProtocolCachePolicy
Specifies that the caching logic defined in the protocol implementation, if any, is used for a particular URL load request. This is the default policy for URL load requests.
Available in Mac OS X v10.2 and later.
Declared in NSURLRequest.h
.
NSURLRequestReloadIgnoringLocalCacheData
Specifies that the data for the URL load should be loaded from the originating source. No existing cache data should be used to satisfy a URL load request.
Available in Mac OS X v10.5 and later.
Declared in NSURLRequest.h
.
NSURLRequestReloadIgnoringLocalAndRemoteCacheData
Specifies that not only should the local cache data be ignored, but that proxies and other intermediates should be instructed to disregard their caches so far as the protocol allows.
Available in Mac OS X v10.5 and later.
Declared in NSURLRequest.h
.
NSURLRequestReloadIgnoringCacheData
Replaced by NSURLRequestReloadIgnoringLocalCacheData
.
Available in Mac OS X v10.2 and later.
Declared in NSURLRequest.h
.
NSURLRequestReturnCacheDataElseLoad
Specifies that the existing cached data should be used to satisfy the request, regardless of its age or expiration date. If there is no existing data in the cache corresponding the request, the data is loaded from the originating source.
Available in Mac OS X v10.2 and later.
Declared in NSURLRequest.h
.
NSURLRequestReturnCacheDataDontLoad
Specifies that the existing cache data should be used to satisfy a request, regardless of its age or expiration date. If there is no existing data in the cache corresponding to a URL load request, no attempt is made to load the data from the originating source, and the load is considered to have failed. This constant specifies a behavior that is similar to an “offline” mode.
Available in Mac OS X v10.2 and later.
Declared in NSURLRequest.h
.
NSURLRequestReloadRevalidatingCacheData
Specifies that the existing cache data may be used provided the origin source confirms its validity, otherwise the URL is loaded from the origin source.
Available in Mac OS X v10.5 and later.
Declared in NSURLRequest.h
.
NSURLRequest.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-01)