Inherits from NSObject
Conforms to AFURLResponseSerialization
Declared in AFURLResponseSerialization.h

Overview

AFHTTPResponseSerializer conforms to the AFURLRequestSerialization & AFURLResponseSerialization protocols, offering a concrete base implementation of query string / URL form-encoded parameter serialization and default request headers, as well as response status code and content type validation.

Any request or response serializer dealing with HTTP is encouraged to subclass AFHTTPResponseSerializer in order to ensure consistent default behavior.

Tasks

Other Methods

  • – init
  •   stringEncoding

    The string encoding used to serialize data received from the server, when no string encoding is specified by the response. NSUTF8StringEncoding by default.

    property
  • + serializer

    Creates and returns a serializer with default configuration.

Configuring Response Serialization

  •   acceptableStatusCodes

    The acceptable HTTP status codes for responses. When non-nil, responses with status codes not contained by the set will result in an error during validation.

    property
  •   acceptableContentTypes

    The acceptable MIME types for responses. When non-nil, responses with a Content-Type with MIME types that do not intersect with the set will result in an error during validation.

    property
  • – validateResponse:data:error:

    Validates the specified response and data.

Properties

acceptableContentTypes

@property (nonatomic, copy) NSSet *acceptableContentTypes
Discussion

The acceptable MIME types for responses. When non-nil, responses with a Content-Type with MIME types that do not intersect with the set will result in an error during validation.

Declared In

AFURLResponseSerialization.h

acceptableStatusCodes

@property (nonatomic, copy) NSIndexSet *acceptableStatusCodes
Discussion

The acceptable HTTP status codes for responses. When non-nil, responses with status codes not contained by the set will result in an error during validation.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Declared In

AFURLResponseSerialization.h

stringEncoding

@property (nonatomic, assign) NSStringEncoding stringEncoding
Discussion

The string encoding used to serialize data received from the server, when no string encoding is specified by the response. NSUTF8StringEncoding by default.

Declared In

AFURLResponseSerialization.h

Class Methods

serializer

+ (instancetype)serializer
Discussion

Creates and returns a serializer with default configuration.

Declared In

AFURLResponseSerialization.h

Instance Methods

init

- (instancetype)init

validateResponse:data:error:

- (BOOL)validateResponse:(NSHTTPURLResponse *)response data:(NSData *)data error:(NSError *__autoreleasing *)error
Discussion

Validates the specified response and data.

In its base implementation, this method checks for an acceptable status code and content type. Subclasses may wish to add other domain-specific checks.

Parameters

response

The response to be validated.

data

The data associated with the response.

error

The error that occurred while attempting to validate the response.

Return Value

YES if the response is valid, otherwise NO.

Declared In

AFURLResponseSerialization.h