AFHTTPRequestOperation Class Reference
Inherits from | AFURLConnectionOperation : NSOperation |
Declared in | AFHTTPRequestOperation.h |
Overview
AFHTTPRequestOperation
is a subclass of AFURLConnectionOperation
for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.
Tasks
Getting HTTP URL Connection Information
-
response
The last HTTP response received by the operation’s connection.
property
Managing And Checking For Acceptable HTTP Responses
-
hasAcceptableStatusCode
A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns
propertyYES
ifacceptableStatusCodes
isnil
. -
hasAcceptableContentType
A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns
propertyYES
ifacceptableContentTypes
isnil
. -
successCallbackQueue
The callback dispatch queue on success. If
propertyNULL
(default), the main queue is used. -
failureCallbackQueue
The callback dispatch queue on failure. If
propertyNULL
(default), the main queue is used.
Managing Acceptable HTTP Status Codes & Content Types
-
+ acceptableStatusCodes
Returns an
NSIndexSet
object containing the ranges of acceptable HTTP status codes. When non-nil
, the operation will set theerror
property to an error inAFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html -
+ addAcceptableStatusCodes:
Adds status codes to the set of acceptable HTTP status codes returned by
acceptableStatusCodes
in subsequent calls by this class and its descendants. -
+ acceptableContentTypes
Returns an
NSSet
object containing the acceptable MIME types. When non-nil
, the operation will set theerror
property to an error inAFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17 -
+ addAcceptableContentTypes:
Adds content types to the set of acceptable MIME types returned by
acceptableContentTypes
in subsequent calls by this class and its descendants.
Determining Whether A Request Can Be Processed
-
+ canProcessRequest:
A Boolean value determining whether or not the class can process the specified request. For example,
AFJSONRequestOperation
may check to make sure the content type wasapplication/json
or the URL path extension was.json
.
Setting Completion Block Success / Failure Callbacks
-
– setCompletionBlockWithSuccess:failure:
Sets the
completionBlock
property with a block that executes either the specified success or failure block, depending on the state of the request on completion. Iferror
returns a value, which can be caused by an unacceptable status code or content type, thenfailure
is executed. Otherwise,success
is executed.
Properties
failureCallbackQueue
The callback dispatch queue on failure. If NULL
(default), the main queue is used.
@property (nonatomic, assign) dispatch_queue_t failureCallbackQueue
Discussion
The callback dispatch queue on failure. If NULL
(default), the main queue is used.
Declared In
AFHTTPRequestOperation.h
hasAcceptableContentType
A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns YES
if acceptableContentTypes
is nil
.
@property (nonatomic, readonly) BOOL hasAcceptableContentType
Discussion
A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns YES
if acceptableContentTypes
is nil
.
Declared In
AFHTTPRequestOperation.h
hasAcceptableStatusCode
A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns YES
if acceptableStatusCodes
is nil
.
@property (nonatomic, readonly) BOOL hasAcceptableStatusCode
Discussion
A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns YES
if acceptableStatusCodes
is nil
.
Declared In
AFHTTPRequestOperation.h
response
The last HTTP response received by the operation’s connection.
@property (readonly, nonatomic, strong) NSHTTPURLResponse *response
Discussion
The last HTTP response received by the operation’s connection.
Declared In
AFHTTPRequestOperation.h
successCallbackQueue
The callback dispatch queue on success. If NULL
(default), the main queue is used.
@property (nonatomic, assign) dispatch_queue_t successCallbackQueue
Discussion
The callback dispatch queue on success. If NULL
(default), the main queue is used.
Declared In
AFHTTPRequestOperation.h
Class Methods
acceptableContentTypes
Returns an NSSet
object containing the acceptable MIME types. When non-nil
, the operation will set the error
property to an error in AFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
+ (NSSet *)acceptableContentTypes
Discussion
Returns an NSSet
object containing the acceptable MIME types. When non-nil
, the operation will set the error
property to an error in AFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
By default, this is nil
.
Declared In
AFHTTPRequestOperation.h
acceptableStatusCodes
Returns an NSIndexSet
object containing the ranges of acceptable HTTP status codes. When non-nil
, the operation will set the error
property to an error in AFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+ (NSIndexSet *)acceptableStatusCodes
Discussion
Returns an NSIndexSet
object containing the ranges of acceptable HTTP status codes. When non-nil
, the operation will set the error
property to an error in AFErrorDomain
. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
By default, this is the range 200 to 299, inclusive.
Declared In
AFHTTPRequestOperation.h
addAcceptableContentTypes:
Adds content types to the set of acceptable MIME types returned by acceptableContentTypes
in subsequent calls by this class and its descendants.
+ (void)addAcceptableContentTypes:(NSSet *)contentTypes
Parameters
- contentTypes
The content types to be added to the set of acceptable MIME types
Discussion
Adds content types to the set of acceptable MIME types returned by acceptableContentTypes
in subsequent calls by this class and its descendants.
Declared In
AFHTTPRequestOperation.h
addAcceptableStatusCodes:
Adds status codes to the set of acceptable HTTP status codes returned by acceptableStatusCodes
in subsequent calls by this class and its descendants.
+ (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes
Parameters
- statusCodes
The status codes to be added to the set of acceptable HTTP status codes
Discussion
Adds status codes to the set of acceptable HTTP status codes returned by acceptableStatusCodes
in subsequent calls by this class and its descendants.
Declared In
AFHTTPRequestOperation.h
canProcessRequest:
A Boolean value determining whether or not the class can process the specified request. For example, AFJSONRequestOperation
may check to make sure the content type was application/json
or the URL path extension was .json
.
+ (BOOL)canProcessRequest:(NSURLRequest *)urlRequest
Parameters
- urlRequest
The request that is determined to be supported or not supported for this class.
Discussion
A Boolean value determining whether or not the class can process the specified request. For example, AFJSONRequestOperation
may check to make sure the content type was application/json
or the URL path extension was .json
.
Declared In
AFHTTPRequestOperation.h
Instance Methods
setCompletionBlockWithSuccess:failure:
Sets the completionBlock
property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If error
returns a value, which can be caused by an unacceptable status code or content type, then failure
is executed. Otherwise, success
is executed.
- (void)setCompletionBlockWithSuccess:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failure
Parameters
- success
The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request.
- failure
The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request.
@discussion This method should be overridden in subclasses in order to specify the response object passed into the success block.
Discussion
Sets the completionBlock
property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If error
returns a value, which can be caused by an unacceptable status code or content type, then failure
is executed. Otherwise, success
is executed.
Declared In
AFHTTPRequestOperation.h