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 | NSURLResponse.h |
Related sample code |
NSURLResponse
declares the programmatic interface for an object that accesses the response returned by an NSURLRequest
instance.
NSURLResponse
encapsulates the metadata associated with a URL load in a manner independent of protocol and URL scheme.
NSHTTPURLResponse
is a subclass of NSURLResponse
that provides methods for accessing information specific to HTTP protocol responses. An NSHTTPURLResponse
object represents a response to an HTTP URL load request.
Note: NSURLResponse
objects do not contain the actual bytes representing the content of a URL. See NSURLConnection
for more information about receiving the content data for a URL load.
Returns the receiver’s expected content length
- (long long)expectedContentLength
The receiver’s expected content length, or NSURLResponseUnknownLength
if the length can’t be determined.
Some protocol implementations report the content length as part of the response, but not all protocols guarantee to deliver that amount of data. Clients should be prepared to deal with more or less data.
NSURLResponse.h
Returns an initialized NSURLResponse
object with the URL, MIME type, length, and text encoding set to given values.
- (id)initWithURL:(NSURL *)URL MIMEType:(NSString *)MIMEType expectedContentLength:(NSInteger)length textEncodingName:(NSString *)name
The URL for the new object.
The MIME type.
The expected content length.This value should be –1
if the expected length is undetermined
The text encoding name. This value may be nil
.
An initialized NSURLResponse
object with the URL set to URL, the MIME type set to MIMEType, length set to length, and text encoding name set to name.
This is the designated initializer for NSURLResponse
.
NSURLResponse.h
Returns the receiver’s MIME type.
- (NSString *)MIMEType
The receiver’s MIME type.
The MIME type is often provided by the response’s originating source. However, that value may be changed or corrected by a protocol implementation if it can be determined that the response’s source reported the information incorrectly.
If the response’s originating source does not provide a MIME type, an attempt to guess the MIME type may be made.
NSURLResponse.h
Returns a suggested filename for the response data.
- (NSString *)suggestedFilename
A suggested filename for the response data.
The method tries to create a filename using the following, in order:
A filename specified using the content disposition header.
The last path component of the URL.
The host of the URL.
If the host of URL can't be converted to a valid filename, the filename “unknown” is used.
In most cases, this method appends the proper file extension based on the MIME type. This method will always return a valid filename regardless of whether or not the resource is saved to disk.
NSURLResponse.h
Returns the name of the receiver’s text encoding provided by the response’s originating source.
- (NSString *)textEncodingName
The name of the receiver’s text encoding provided by the response’s originating source, or nil
if no text encoding was provided by the protocol
Clients can convert this string to an NSStringEncoding
or a CFStringEncoding
using the methods and functions available in the appropriate framework.
NSURLResponse.h
Returns the receiver’s URL.
- (NSURL *)URL
The receiver’s URL.
NSURLResponse.h
The following error code is returned by expectedContentLength
.
#define NSURLResponseUnknownLength ((long long)-1)
NSURLResponseUnknownLength
Returned when the response length cannot be determined in advance of receiving the data from the server. For example, NSURLResponseUnknownLength
is returned when the server HTTP response does not include a Content-Length header.
Available in Mac OS X v10.2 and later.
Declared in NSURLResponse.h
.
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)