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

Managing Acceptable HTTP Status Codes & Content Types

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 was application/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. 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.

Properties

failureCallbackQueue

@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

@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

@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

@property (readonly, nonatomic, strong) NSHTTPURLResponse *response
Discussion

The last HTTP response received by the operation’s connection.

Declared In

AFHTTPRequestOperation.h

successCallbackQueue

@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

+ (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

+ (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:

+ (void)addAcceptableContentTypes:(NSSet *)contentTypes
Discussion

Adds content types to the set of acceptable MIME types returned by acceptableContentTypes in subsequent calls by this class and its descendants.

Parameters

contentTypes

The content types to be added to the set of acceptable MIME types

Declared In

AFHTTPRequestOperation.h

addAcceptableStatusCodes:

+ (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes
Discussion

Adds status codes to the set of acceptable HTTP status codes returned by acceptableStatusCodes in subsequent calls by this class and its descendants.

Parameters

statusCodes

The status codes to be added to the set of acceptable HTTP status codes

Declared In

AFHTTPRequestOperation.h

canProcessRequest:

+ (BOOL)canProcessRequest:(NSURLRequest *)urlRequest
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.

Parameters

urlRequest

The request that is determined to be supported or not supported for this class.

Declared In

AFHTTPRequestOperation.h

Instance Methods

setCompletionBlockWithSuccess:failure:

- (void)setCompletionBlockWithSuccess:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failure
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.

This method should be overridden in subclasses in order to specify the response object passed into the success block.

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.

Declared In

AFHTTPRequestOperation.h