AFHTTPClient Class Reference
| Inherits from | NSObject |
| Conforms to | NSCoding NSCopying |
| Declared in | AFHTTPClient.h AFHTTPClient.m |
Overview
AFHTTPClient captures the common patterns of communicating with an web application over HTTP. It encapsulates information like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations.
Automatic Content Parsing
Instances of AFHTTPClient may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly in enqueueHTTPRequestOperationWithRequest:success:failure.
Subclassing Notes
In most cases, one should create an AFHTTPClient subclass for each website or web application that your application communicates with. It is often useful, also, to define a class method that returns a singleton shared HTTP client in each subclass, that persists authentication credentials and other configuration across the entire application.
Methods to Override
To change the behavior of all url request construction for an AFHTTPClient subclass, override requestWithMethod:path:parameters.
To change the behavior of all request operation construction for an AFHTTPClient subclass, override HTTPRequestOperationWithRequest:success:failure.
Default Headers
By default, AFHTTPClient sets the following HTTP headers:
Accept-Language: (comma-delimited preferred languages), en-us;q=0.8User-Agent: (generated user agent)
You can override these HTTP headers or define new ones using setDefaultHeader:value:.
URL Construction Using Relative Paths
Both requestWithMethod:path:parameters: and multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock: construct URLs from the path relative to the baseURL, using NSURL +URLWithString:relativeToURL:. Below are a few examples of how baseURL and relative paths interact:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"]http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
Also important to note is that a trailing slash will be added to any baseURL without one, which would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash.
NSCoding / NSCopying Conformance
AFHTTPClient conforms to the NSCoding and NSCopying protocols, allowing operations to be archived to disk, and copied in memory, respectively. There are a few minor caveats to keep in mind, however:
- Archives and copies of HTTP clients will be initialized with an empty operation queue.
- NSCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
Tasks
Accessing HTTP Client Properties
-
baseURLThe url used as the base for paths specified in methods such as
propertygetPath:parameters:success:failure -
stringEncodingThe string encoding used in constructing url requests. This is
propertyNSUTF8StringEncodingby default. -
parameterEncodingThe
propertyAFHTTPClientParameterEncodingvalue corresponding to how parameters are encoded into a request body. This isAFFormURLParameterEncodingby default. -
operationQueueThe operation queue which manages operations enqueued by the HTTP client.
property -
networkReachabilityStatusThe reachability status from the device to the current
propertybaseURLof theAFHTTPClient.
Creating and Initializing HTTP Clients
-
+ clientWithBaseURL:Creates and initializes an
AFHTTPClientobject with the specified base URL. -
– initWithBaseURL:Initializes an
AFHTTPClientobject with the specified base URL.
Managing Reachability Status
-
– setReachabilityStatusChangeBlock:Sets a callback to be executed when the network availability of the
baseURLhost changes.
Managing HTTP Operations
-
– registerHTTPOperationClass:Attempts to register a subclass of
AFHTTPRequestOperation, adding it to a chain to automatically generate request operations from a URL request. -
– unregisterHTTPOperationClass:Unregisters the specified subclass of
AFHTTPRequestOperationfrom the chain of classes consulted when-requestWithMethod:path:parametersis called.
Managing HTTP Header Values
-
– defaultValueForHeader:Returns the value for the HTTP headers set in request objects created by the HTTP client.
-
– setDefaultHeader:value:Sets the value for the HTTP headers set in request objects made by the HTTP client. If
nil, removes the existing value for that header. -
– setAuthorizationHeaderWithUsername:password:Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
-
– setAuthorizationHeaderWithToken:Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
-
– clearAuthorizationHeaderClears any existing value for the “Authorization” HTTP header.
Creating Request Objects
-
– requestWithMethod:path:parameters:Creates an
NSMutableURLRequestobject with the specified HTTP method and path. -
– multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:Creates an
NSMutableURLRequestobject with the specified HTTP method and path, and constructs amultipart/form-dataHTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2
Creating HTTP Operations
Managing Enqueued HTTP Operations
-
– enqueueHTTPRequestOperation:Enqueues an
AFHTTPRequestOperationto the HTTP client’s operation queue. -
– cancelAllHTTPOperationsWithMethod:path:Cancels all operations in the HTTP client’s operation queue whose URLs match the specified HTTP method and path.
Batching HTTP Request Operations
-
– enqueueBatchOfHTTPRequestOperationsWithRequests:progressBlock:completionBlock:Creates and enqueues an
AFHTTPRequestOperationto the HTTP client’s operation queue for each specified request object into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes. -
– enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:Enqueues the specified request operations into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.
Making HTTP Requests
-
– getPath:parameters:success:failure:Creates an
AFHTTPRequestOperationwith aGETrequest, and enqueues it to the HTTP client’s operation queue. -
– postPath:parameters:success:failure:Creates an
AFHTTPRequestOperationwith aPOSTrequest, and enqueues it to the HTTP client’s operation queue. -
– putPath:parameters:success:failure:Creates an
AFHTTPRequestOperationwith aPUTrequest, and enqueues it to the HTTP client’s operation queue. -
– deletePath:parameters:success:failure:Creates an
AFHTTPRequestOperationwith aDELETErequest, and enqueues it to the HTTP client’s operation queue. -
– patchPath:parameters:success:failure:Creates an
AFHTTPRequestOperationwith aPATCHrequest, and enqueues it to the HTTP client’s operation queue.
Properties
baseURL
The url used as the base for paths specified in methods such as getPath:parameters:success:failure
@property (readonly, nonatomic) NSURL *baseURLDiscussion
The url used as the base for paths specified in methods such as getPath:parameters:success:failure
Declared In
AFHTTPClient.hnetworkReachabilityStatus
The reachability status from the device to the current baseURL of the AFHTTPClient.
@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatusDiscussion
The reachability status from the device to the current baseURL of the AFHTTPClient.
Warning: This property requires the SystemConfiguration framework. Add it in the active target’s “Link Binary With Library” build phase, and add #import <SystemConfiguration/SystemConfiguration.h> to the header prefix of the project (Prefix.pch).
Declared In
AFHTTPClient.hoperationQueue
The operation queue which manages operations enqueued by the HTTP client.
@property (readonly, nonatomic) NSOperationQueue *operationQueueDiscussion
The operation queue which manages operations enqueued by the HTTP client.
Declared In
AFHTTPClient.hparameterEncoding
The AFHTTPClientParameterEncoding value corresponding to how parameters are encoded into a request body. This is AFFormURLParameterEncoding by default.
@property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncodingDiscussion
The AFHTTPClientParameterEncoding value corresponding to how parameters are encoded into a request body. This is AFFormURLParameterEncoding by default.
Warning: Some nested parameter structures, such as a keyed array of hashes containing inconsistent keys (i.e. @{@"": @[@{@"a" : @(1)}, @{@"b" : @(2)}]}), cannot be unambiguously represented in query strings. It is strongly recommended that an unambiguous encoding, such as AFJSONParameterEncoding, is used when posting complicated or nondeterministic parameter structures.
Declared In
AFHTTPClient.hstringEncoding
The string encoding used in constructing url requests. This is NSUTF8StringEncoding by default.
@property (nonatomic, assign) NSStringEncoding stringEncodingDiscussion
The string encoding used in constructing url requests. This is NSUTF8StringEncoding by default.
Declared In
AFHTTPClient.hClass Methods
clientWithBaseURL:
Creates and initializes an AFHTTPClient object with the specified base URL.
+ (AFHTTPClient *)clientWithBaseURL:(NSURL *)urlParameters
- url
The base URL for the HTTP client. This argument must not be
nil.
Return Value
The newly-initialized HTTP client
Discussion
Creates and initializes an AFHTTPClient object with the specified base URL.
Declared In
AFHTTPClient.hInstance Methods
HTTPRequestOperationWithRequest:success:failure:
Creates an AFHTTPRequestOperation.
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- urlRequest
The request object to be loaded asynchronously during execution of the operation.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation.
In order to determine what kind of operation is created, each registered subclass conforming to the AFHTTPClient protocol is consulted (in reverse order of when they were specified) to see if it can handle the specific request. The first class to return YES when sent a canProcessRequest: message is used to generate an operation using HTTPRequestOperationWithRequest:success:failure:.
Declared In
AFHTTPClient.hcancelAllHTTPOperationsWithMethod:path:
Cancels all operations in the HTTP client’s operation queue whose URLs match the specified HTTP method and path.
- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method path:(NSString *)pathParameters
- method
The HTTP method to match for the cancelled requests, such as
GET,POST,PUT, orDELETE. Ifnil, all request operations with URLs matching the path will be cancelled.
- path
The path appended to the HTTP client base URL to match against the cancelled requests. If
nil, no path will be appended to the base URL.@discussion This method only cancels
AFHTTPRequestOperationswhose request URL matches the HTTP client base URL with the path appended. For complete control over the lifecycle of enqueued operations, you can access theoperationQueueproperty directly, which allows you to, for instance, cancel operations filtered by a predicate, or simply use-cancelAllRequests. Note that the operation queue may include non-HTTP operations, so be sure to check the type before attempting to directly introspect an operation’srequestproperty.
Discussion
Cancels all operations in the HTTP client’s operation queue whose URLs match the specified HTTP method and path.
Declared In
AFHTTPClient.hclearAuthorizationHeader
Clears any existing value for the “Authorization” HTTP header.
- (void)clearAuthorizationHeaderDiscussion
Clears any existing value for the “Authorization” HTTP header.
Declared In
AFHTTPClient.hdefaultValueForHeader:
Returns the value for the HTTP headers set in request objects created by the HTTP client.
- (NSString *)defaultValueForHeader:(NSString *)headerParameters
- header
The HTTP header to return the default value for
Return Value
The default value for the HTTP header, or nil if unspecified
Discussion
Returns the value for the HTTP headers set in request objects created by the HTTP client.
Declared In
AFHTTPClient.hdeletePath:parameters:success:failure:
Creates an AFHTTPRequestOperation with a DELETE request, and enqueues it to the HTTP client’s operation queue.
- (void)deletePath:(NSString *)path parameters:(NSDictionary *)parameters success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and appended as the query string for the request URL.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation with a DELETE request, and enqueues it to the HTTP client’s operation queue.
Declared In
AFHTTPClient.henqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:
Enqueues the specified request operations into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.
- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations progressBlock:(void ( ^ ) ( NSUInteger numberOfFinishedOperations , NSUInteger totalNumberOfOperations ))progressBlock completionBlock:(void ( ^ ) ( NSArray *operations ))completionBlockParameters
- operations
The request operations used to be batched and enqueued.
- progressBlock
A block object to be executed upon the completion of each request operation in the batch. This block has no return value and takes two arguments: the number of operations that have already finished execution, and the total number of operations.
- completionBlock
A block object to be executed upon the completion of all of the request operations in the batch. This block has no return value and takes a single argument: the batched request operations.
Discussion
Enqueues the specified request operations into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.
Declared In
AFHTTPClient.henqueueBatchOfHTTPRequestOperationsWithRequests:progressBlock:completionBlock:
Creates and enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue for each specified request object into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.
- (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)urlRequests progressBlock:(void ( ^ ) ( NSUInteger numberOfFinishedOperations , NSUInteger totalNumberOfOperations ))progressBlock completionBlock:(void ( ^ ) ( NSArray *operations ))completionBlockParameters
- urlRequests
The
NSURLRequestobjects used to create and enqueue operations.
- progressBlock
A block object to be executed upon the completion of each request operation in the batch. This block has no return value and takes two arguments: the number of operations that have already finished execution, and the total number of operations.
- completionBlock
A block object to be executed upon the completion of all of the request operations in the batch. This block has no return value and takes a single argument: the batched request operations.
@discussion Operations are created by passing the specified
NSURLRequestobjects inrequests, usingHTTPRequestOperationWithRequest:success:failure:, withnilfor both thesuccessandfailureparameters.
Discussion
Creates and enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue for each specified request object into a batch. When each request operation finishes, the specified progress block is executed, until all of the request operations have finished, at which point the completion block also executes.
Declared In
AFHTTPClient.henqueueHTTPRequestOperation:
Enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue.
- (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operationParameters
- operation
The HTTP request operation to be enqueued.
Discussion
Enqueues an AFHTTPRequestOperation to the HTTP client’s operation queue.
Declared In
AFHTTPClient.hgetPath:parameters:success:failure:
Creates an AFHTTPRequestOperation with a GET request, and enqueues it to the HTTP client’s operation queue.
- (void)getPath:(NSString *)path parameters:(NSDictionary *)parameters success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and appended as the query string for the request URL.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation with a GET request, and enqueues it to the HTTP client’s operation queue.
Declared In
AFHTTPClient.hinitWithBaseURL:
Initializes an AFHTTPClient object with the specified base URL.
- (id)initWithBaseURL:(NSURL *)urlParameters
- url
The base URL for the HTTP client. This argument must not be
nil.@discussion This is the designated initializer.
Return Value
The newly-initialized HTTP client
Discussion
Initializes an AFHTTPClient object with the specified base URL.
Declared In
AFHTTPClient.hmultipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:
Creates an NSMutableURLRequest object with the specified HTTP method and path, and constructs a multipart/form-data HTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2
- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters constructingBodyWithBlock:(void ( ^ ) ( id<AFMultipartFormData> formData ))blockParameters
- method
The HTTP method for the request. This parameter must not be
GETorHEAD, ornil.
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and set in the request HTTP body.
- block
A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the
AFMultipartFormDataprotocol. This can be used to upload files, encode HTTP body as JSON or XML, or specify multiple values for the same parameter, as one might for array values.@discussion Multipart form requests are automatically streamed, reading files directly from disk along with in-memory data in a single HTTP body. The resulting
NSMutableURLRequestobject has anHTTPBodyStreamproperty, so refrain from settingHTTPBodyStreamorHTTPBodyon this request object, as it will clear out the multipart form body stream.
Return Value
An NSMutableURLRequest object
Discussion
Creates an NSMutableURLRequest object with the specified HTTP method and path, and constructs a multipart/form-data HTTP body, using the specified parameters and multipart form data block. See http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.2
Declared In
AFHTTPClient.hpatchPath:parameters:success:failure:
Creates an AFHTTPRequestOperation with a PATCH request, and enqueues it to the HTTP client’s operation queue.
- (void)patchPath:(NSString *)path parameters:(NSDictionary *)parameters success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and set in the request HTTP body.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation with a PATCH request, and enqueues it to the HTTP client’s operation queue.
Declared In
AFHTTPClient.hpostPath:parameters:success:failure:
Creates an AFHTTPRequestOperation with a POST request, and enqueues it to the HTTP client’s operation queue.
- (void)postPath:(NSString *)path parameters:(NSDictionary *)parameters success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and set in the request HTTP body.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation with a POST request, and enqueues it to the HTTP client’s operation queue.
Declared In
AFHTTPClient.hputPath:parameters:success:failure:
Creates an AFHTTPRequestOperation with a PUT request, and enqueues it to the HTTP client’s operation queue.
- (void)putPath:(NSString *)path parameters:(NSDictionary *)parameters success:(void ( ^ ) ( AFHTTPRequestOperation *operation , id responseObject ))success failure:(void ( ^ ) ( AFHTTPRequestOperation *operation , NSError *error ))failureParameters
- path
The path to be appended to the HTTP client’s base URL and used as the request URL.
- parameters
The parameters to be encoded and set in the request HTTP body.
- success
A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request.
- failure
A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the
NSErrorobject describing the network or parsing error that occurred.
Discussion
Creates an AFHTTPRequestOperation with a PUT request, and enqueues it to the HTTP client’s operation queue.
Declared In
AFHTTPClient.hregisterHTTPOperationClass:
Attempts to register a subclass of AFHTTPRequestOperation, adding it to a chain to automatically generate request operations from a URL request.
- (BOOL)registerHTTPOperationClass:(Class)operationClassParameters
- operationClass
The subclass of
AFHTTPRequestOperationto register
Return Value
YES if the registration is successful, NO otherwise. The only failure condition is if operationClass is not a subclass of AFHTTPRequestOperation.
@discussion When enqueueHTTPRequestOperationWithRequest:success:failure is invoked, each registered class is consulted in turn to see if it can handle the specific request. The first class to return YES when sent a canProcessRequest: message is used to create an operation using initWithURLRequest: and do setCompletionBlockWithSuccess:failure:. There is no guarantee that all registered classes will be consulted. Classes are consulted in the reverse order of their registration. Attempting to register an already-registered class will move it to the top of the list.
Discussion
Attempts to register a subclass of AFHTTPRequestOperation, adding it to a chain to automatically generate request operations from a URL request.
Declared In
AFHTTPClient.hrequestWithMethod:path:parameters:
Creates an NSMutableURLRequest object with the specified HTTP method and path.
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parametersParameters
- method
The HTTP method for the request, such as
GET,POST,PUT, orDELETE. This parameter must not benil.
- path
The path to be appended to the HTTP client’s base URL and used as the request URL. If
nil, no path will be appended to the base URL.
- parameters
The parameters to be either set as a query string for
GETrequests, or the request HTTP body.
Return Value
An NSMutableURLRequest object
Discussion
Creates an NSMutableURLRequest object with the specified HTTP method and path.
If the HTTP method is GET, HEAD, or DELETE, the parameters will be used to construct a url-encoded query string that is appended to the request’s URL. Otherwise, the parameters will be encoded according to the value of the parameterEncoding property, and set as the request body.
Declared In
AFHTTPClient.hsetAuthorizationHeaderWithToken:
Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
- (void)setAuthorizationHeaderWithToken:(NSString *)tokenParameters
- token
The authentication token
Discussion
Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a token-based authentication value, such as an OAuth access token. This overwrites any existing value for this header.
Declared In
AFHTTPClient.hsetAuthorizationHeaderWithUsername:password:
Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
- (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)passwordParameters
- username
The HTTP basic auth username
- password
The HTTP basic auth password
Discussion
Sets the “Authorization” HTTP header set in request objects made by the HTTP client to a basic authentication value with Base64-encoded username and password. This overwrites any existing value for this header.
Declared In
AFHTTPClient.hsetDefaultHeader:value:
Sets the value for the HTTP headers set in request objects made by the HTTP client. If nil, removes the existing value for that header.
- (void)setDefaultHeader:(NSString *)header value:(NSString *)valueParameters
- header
The HTTP header to set a default value for
- value
The value set as default for the specified header, or `nil
Discussion
Sets the value for the HTTP headers set in request objects made by the HTTP client. If nil, removes the existing value for that header.
Declared In
AFHTTPClient.hsetReachabilityStatusChangeBlock:
Sets a callback to be executed when the network availability of the baseURL host changes.
- (void)setReachabilityStatusChangeBlock:(void ( ^ ) ( AFNetworkReachabilityStatus status ))blockParameters
Discussion
Sets a callback to be executed when the network availability of the baseURL host changes.
Warning: This method requires the SystemConfiguration framework. Add it in the active target’s “Link Binary With Library” build phase, and add #import <SystemConfiguration/SystemConfiguration.h> to the header prefix of the project (Prefix.pch).
Declared In
AFHTTPClient.hunregisterHTTPOperationClass:
Unregisters the specified subclass of AFHTTPRequestOperation from the chain of classes consulted when -requestWithMethod:path:parameters is called.
- (void)unregisterHTTPOperationClass:(Class)operationClassParameters
- operationClass
The subclass of
AFHTTPRequestOperationto register
Discussion
Unregisters the specified subclass of AFHTTPRequestOperation from the chain of classes consulted when -requestWithMethod:path:parameters is called.
Declared In
AFHTTPClient.h