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
  •   responseSerializer

    Responses sent from the server in data tasks created with dataTaskWithRequest:success:failure: and run using the GET / POST / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to a compound serializer, which serializes data from responses with either a application/json or application/x-plist MIME type, and falls back to the raw data object. The serializer validates the status code to be in the 2XX range, denoting success. If the response serializer generates an error in -responseObjectForResponse:data:error:, the failure callback of the session task or request operation will be executed; otherwise, the success callback will be executed.

    property

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

response

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

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

Declared In

AFHTTPRequestOperation.h

responseSerializer

@property (nonatomic, strong) AFHTTPResponseSerializer<AFURLResponseSerialization> *responseSerializer
Discussion

Responses sent from the server in data tasks created with dataTaskWithRequest:success:failure: and run using the GET / POST / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to a compound serializer, which serializes data from responses with either a application/json or application/x-plist MIME type, and falls back to the raw data object. The serializer validates the status code to be in the 2XX range, denoting success. If the response serializer generates an error in -responseObjectForResponse:data:error:, the failure callback of the session task or request operation will be executed; otherwise, the success callback will be executed.

Warning: responseSerializer must not be nil.

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