2011-09-21 22:42:01 -05:00
// AFHTTPClient.h
2011-06-01 11:51:53 -05:00
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
# import <Foundation / Foundation.h>
2011-10-10 10:51:23 -05:00
@ class AFHTTPRequestOperation ;
@ protocol AFHTTPClientOperation ;
2011-09-26 11:50:13 -05:00
@ protocol AFMultipartFormData ;
2011-08-05 10:58:37 -05:00
2011-10-11 16:47:59 -05:00
/**
Method used to encode parameters into request body
*/
2011-10-06 14:33:16 -05:00
typedef enum {
AFFormURLParameterEncoding ,
AFJSONParameterEncoding ,
AFPropertyListParameterEncoding ,
} AFHTTPClientParameterEncoding ;
2011-11-09 11:43:02 -06:00
/**
Returns a string , replacing certain characters with the equivalent percent escape sequence based on the specified encoding .
@ param string The string to URL encode
@ param encoding The encoding to use for the replacement . If you are uncertain of the correct encoding , you should use UTF - 8 ( NSUTF8StringEncoding ) , which is the encoding designated by RFC 3986 as the correct encoding for use in URLs .
@ discussion The characters escaped are all characters that are not legal URL characters ( based on RFC 3986 ) , including any whitespace , punctuation , or special characters .
@ return A URL - encoded string . If it does not need to be modified ( no percent escape sequences are missing ) , this function may merely return string argument .
*/
extern NSString * AFURLEncodedStringFromStringWithEncoding ( NSString * string , NSStringEncoding encoding ) ;
/**
Returns a query string constructed by a set of parameters , using the specified encoding .
@ param parameters The parameters used to construct the query string
@ param encoding The encoding to use in constructing the query string . If you are uncertain of the correct encoding , you should use UTF - 8 ( NSUTF8StringEncoding ) , which is the encoding designated by RFC 3986 as the correct encoding for use in URLs .
@ discussion Query strings are constructed by collecting each key - value pair , URL - encoding the string value of the key and value ( by sending ` - description ` to each ) , constructing a string in the form " key=value " , and then joining the components with " & " . The constructed query string does not include the ? character used to delimit the query component .
@ return A URL - encoded query string
*/
extern NSString * AFQueryStringFromParametersWithEncoding ( NSDictionary * parameters , NSStringEncoding encoding ) ;
2011-09-21 23:16:35 -05:00
/**
2011-10-11 16:47:59 -05:00
` 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
2011-10-12 11:07:01 -05:00
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 ` . See ` AFHTTPClientOperation ` for further details .
2011-10-11 16:47:59 -05:00
# # 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
2011-09-26 12:51:20 -05:00
2011-10-12 11:07:01 -05:00
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 ` enqueueHTTPRequestOperationWithRequest : success : failure ` .
2011-10-11 16:47:59 -05:00
# # Default Headers
By default , ` AFHTTPClient ` sets the following HTTP headers :
2011-09-26 12:51:20 -05:00
- ` Accept - Encoding : gzip `
2011-10-12 11:46:56 -05:00
- ` Accept - Language : ( [ NSLocale preferredLanguages ] ) , en - us ; q = 0.8 `
- ` User - Agent : ( generated user agent ) `
2011-09-26 12:51:20 -05:00
2011-11-09 10:51:33 -06:00
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 interract :
2011-11-14 14:24:21 -06:00
NSURL * baseURL = [ NSURL URLWithString : @ " 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/
2011-09-21 23:16:35 -05:00
*/
2011-09-21 22:42:01 -05:00
@ interface AFHTTPClient : NSObject {
2011-09-16 10:02:51 -05:00
@ private
NSURL * _baseURL ;
2011-09-21 11:36:39 -05:00
NSStringEncoding _stringEncoding ;
2011-10-06 14:33:16 -05:00
AFHTTPClientParameterEncoding _parameterEncoding ;
2011-10-05 15:44:51 -05:00
NSMutableArray * _registeredHTTPOperationClassNames ;
2011-07-27 15:14:15 -05:00
NSMutableDictionary * _defaultHeaders ;
NSOperationQueue * _operationQueue ;
}
2011-09-26 12:51:20 -05:00
///---------------------------------------
/// @name Accessing HTTP Client Properties
///---------------------------------------
2011-09-18 15:06:29 -05:00
/**
2011-09-24 21:53:46 -04:00
The url used as the base for paths specified in methods such as ` getPath : parameteres : success : failure `
2011-09-18 15:06:29 -05:00
*/
@ property ( readonly , nonatomic , retain ) NSURL * baseURL ;
2011-09-21 17:51:05 -05:00
/**
The string encoding used in constructing url requests . This is ` NSUTF8StringEncoding ` by default .
*/
2011-09-21 11:36:39 -05:00
@ property ( nonatomic , assign ) NSStringEncoding stringEncoding ;
2011-10-06 14:33:16 -05:00
/**
2011-10-12 10:41:59 -05:00
The ` AFHTTPClientParameterEncoding ` value corresponding to how parameters are encoded into a request body . This is ` AFFormURLParameterEncoding ` by default .
2011-10-06 14:33:16 -05:00
*/
@ property ( nonatomic , assign ) AFHTTPClientParameterEncoding parameterEncoding ;
2011-09-21 17:51:05 -05:00
/**
2011-09-21 23:16:35 -05:00
The operation queue which manages operations enqueued by the HTTP client .
2011-09-21 17:51:05 -05:00
*/
2011-09-26 11:06:56 -05:00
@ property ( readonly , nonatomic , retain ) NSOperationQueue * operationQueue ;
2011-09-21 11:36:39 -05:00
2011-09-22 09:43:58 -05:00
///---------------------------------------------
/// @name Creating and Initializing HTTP Clients
///---------------------------------------------
/**
Creates and initializes an ` AFHTTPClient ` object with the specified base URL .
@ param url The base URL for the HTTP client . This argument must not be nil .
@ return The newly - initialized HTTP client
*/
+ ( AFHTTPClient * ) clientWithBaseURL : ( NSURL * ) url ;
2011-09-18 15:06:29 -05:00
/**
2011-09-21 23:16:35 -05:00
Initializes an ` AFHTTPClient ` object with the specified base URL .
2011-09-18 15:06:29 -05:00
2011-09-21 23:16:35 -05:00
@ param url The base URL for the HTTP client . This argument must not be nil .
2011-09-18 15:06:29 -05:00
2011-10-12 10:41:59 -05:00
@ discussion This is the designated initializer .
2011-09-22 09:43:58 -05:00
2011-09-21 23:16:35 -05:00
@ return The newly - initialized HTTP client
2011-09-18 15:06:29 -05:00
*/
2011-09-16 10:02:51 -05:00
- ( id ) initWithBaseURL : ( NSURL * ) url ;
2011-10-05 15:44:51 -05:00
///----------------------------------
/// @name Managing HTTP Operations
///----------------------------------
2011-10-12 10:41:59 -05:00
/**
2011-10-24 13:08:58 -05:00
Attempts to register a subclass of ` AFHTTPRequestOperation ` , adding it to a chain to automatically generate request operations from a URL request .
2011-10-12 10:41:59 -05:00
2011-10-24 13:08:58 -05:00
@ param The subclass of ` AFHTTPRequestOperation ` to register
2011-10-12 10:41:59 -05:00
2011-10-24 13:08:58 -05:00
@ return ` YES ` if the registration is successful , ` NO ` otherwise . The only failure condition is if ` operationClass ` does is not a subclass of ` AFHTTPRequestOperation ` .
2011-10-12 10:41:59 -05:00
2011-10-24 13:08:58 -05:00
@ 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 .
2011-10-12 10:41:59 -05:00
@ see ` AFHTTPClientOperation `
*/
2011-10-05 15:44:51 -05:00
- ( BOOL ) registerHTTPOperationClass : ( Class ) operationClass ;
2011-10-12 10:41:59 -05:00
/**
2011-10-24 13:08:58 -05:00
Unregisters the specified subclass of ` AFHTTPRequestOperation ` .
2011-10-12 10:41:59 -05:00
@ param The class conforming to the ` AFHTTPClientOperation ` protocol to unregister
@ discussion After this method is invoked , ` operationClass ` is no longer consulted when ` requestWithMethod : path : parameters ` is invoked .
*/
- ( void ) unregisterHTTPOperationClass : ( Class ) operationClass ;
2011-09-18 15:06:29 -05:00
///----------------------------------
/// @name Managing HTTP Header Values
///----------------------------------
/**
2011-09-26 12:51:20 -05:00
Returns the value for the HTTP headers set in request objects created by the HTTP client .
2011-09-18 15:06:29 -05:00
@ param header The HTTP header to return the default value for
@ return The default value for the HTTP header , or ` nil ` if unspecified
*/
2011-06-01 11:51:53 -05:00
- ( NSString * ) defaultValueForHeader : ( NSString * ) header ;
2011-09-18 15:06:29 -05:00
/**
2011-09-21 23:16:35 -05:00
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 .
2011-09-18 15:06:29 -05:00
@ param header The HTTP header to set a default value for
@ param value The value set as default for the specified header , or ` nil
*/
2011-06-01 11:51:53 -05:00
- ( void ) setDefaultHeader : ( NSString * ) header value : ( NSString * ) value ;
2011-09-18 15:06:29 -05:00
/**
2011-09-21 23:16:35 -05:00
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 .
2011-09-18 15:06:29 -05:00
@ param username The HTTP basic auth username
@ param password The HTTP basic auth password
*/
2011-08-24 15:21:17 -05:00
- ( void ) setAuthorizationHeaderWithUsername : ( NSString * ) username password : ( NSString * ) password ;
2011-09-18 15:06:29 -05:00
/**
2011-09-21 23:16:35 -05:00
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 .
2011-09-18 15:06:29 -05:00
@ param token The authentication token
*/
2011-06-01 11:51:53 -05:00
- ( void ) setAuthorizationHeaderWithToken : ( NSString * ) token ;
2011-09-18 15:06:29 -05:00
/**
Clears any existing value for the " Authorization " HTTP header .
*/
2011-06-01 11:51:53 -05:00
- ( void ) clearAuthorizationHeader ;
2011-09-18 15:06:29 -05:00
///-------------------------------
/// @name Creating Request Objects
///-------------------------------
/**
2011-10-11 16:47:59 -05:00
Creates an ` NSMutableURLRequest ` object with the specified HTTP method and path . By default , this method scans through the registered operation classes ( in reverse order of when they were specified ) , until finding one that can handle the specified request .
If the HTTP method is ` GET ` , 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 .
2011-09-18 15:06:29 -05:00
2011-09-21 17:51:05 -05:00
@ param method The HTTP method for the request , such as ` GET ` , ` POST ` , ` PUT ` , or ` DELETE ` .
2011-09-21 23:16:35 -05:00
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
2011-09-21 17:51:05 -05:00
@ param parameters The parameters to be either set as a query string for ` GET ` requests , or the request HTTP body .
2011-11-09 10:51:33 -06:00
@ return An ` NSMutableURLRequest ` object
2011-09-18 15:06:29 -05:00
*/
2011-08-05 10:58:37 -05:00
- ( NSMutableURLRequest * ) requestWithMethod : ( NSString * ) method
2011-09-26 12:51:20 -05:00
path : ( NSString * ) path
parameters : ( NSDictionary * ) parameters ;
2011-07-27 15:14:15 -05:00
2011-09-21 17:51:05 -05:00
/**
2011-09-26 11:50:13 -05:00
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
2011-09-21 17:51:05 -05:00
@ param method The HTTP method for the request . Must be either ` POST ` , ` PUT ` , or ` DELETE ` .
2011-09-21 23:16:35 -05:00
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
2011-09-21 17:51:05 -05:00
@ param parameters The parameters to be encoded and set in the request HTTP body .
2011-09-26 11:50:13 -05:00
@ param block A block that takes a single argument and appends data to the HTTP body . The block argument is an object adopting the ` AFMultipartFormData ` protocol . 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 .
2011-11-09 10:51:33 -06:00
2011-12-13 09:55:37 -06:00
@ discussion The multipart form data is constructed synchronously in the specified block , so in cases where large amounts of data are being added to the request , you should consider performing this method in the background . Likewise , the form data is constructed in - memory , so it may be advantageous to instead write parts of the form data to a file and stream the request body using the ` HTTPBodyStream ` property of ` NSURLRequest ` .
2011-10-11 16:47:59 -05:00
@ warning An exception will be raised if the specified method is not ` POST ` , ` PUT ` or ` DELETE ` .
2011-09-21 17:51:05 -05:00
@ return An ` NSMutableURLRequest ` object
*/
2011-09-21 14:00:05 -05:00
- ( NSMutableURLRequest * ) multipartFormRequestWithMethod : ( NSString * ) method
path : ( NSString * ) path
parameters : ( NSDictionary * ) parameters
2011-09-26 11:50:13 -05:00
constructingBodyWithBlock : ( void ( ^ ) ( id < AFMultipartFormData > formData ) ) block ;
2011-09-21 14:00:05 -05:00
2011-11-07 11:43:19 -06:00
///-------------------------------
/// @name Creating HTTP Operations
///-------------------------------
2011-09-16 10:06:11 -05:00
2011-09-21 17:51:05 -05:00
/**
2011-11-07 11:43:19 -06:00
Creates an ` AFHTTPRequestOperation `
2011-09-21 17:51:05 -05:00
2011-11-10 11:03:02 -06:00
In order to determine what kind of operation is created , each registered subclass conforming to the ` AFHTTPClient ` protocol 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 generate an operation using ` HTTPRequestOperationWithRequest : success : failure : ` .
2011-11-07 11:43:19 -06:00
2011-09-21 17:51:05 -05:00
@ param request The request object to be loaded asynchronously during execution of the operation .
2011-11-10 11:03:02 -06:00
@ param 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 .
@ param failure A block object to be executed when the request operation finishes unsuccessfully , or that finishes successfully , but encountered an error while parsing the resonse data . This block has no return value and takes two arguments : , the created request operation and the ` NSError ` object describing the network or parsing error that occurred .
2011-09-21 17:51:05 -05:00
*/
2011-11-07 11:43:19 -06:00
- ( AFHTTPRequestOperation * ) HTTPRequestOperationWithRequest : ( NSURLRequest * ) request
success : ( void ( ^ ) ( AFHTTPRequestOperation * operation , id responseObject ) ) success
failure : ( void ( ^ ) ( AFHTTPRequestOperation * operation , NSError * error ) ) failure ;
///----------------------------------------
/// @name Managing Enqueued HTTP Operations
///----------------------------------------
2011-10-06 14:33:16 -05:00
/**
2011-10-12 11:07:01 -05:00
Enqueues an ` AFHTTPRequestOperation ` to the HTTP client ' s operation queue .
@ param operation The HTTP request operation to be enqueued .
2011-10-06 14:33:16 -05:00
*/
- ( void ) enqueueHTTPRequestOperation : ( AFHTTPRequestOperation * ) operation ;
2011-07-27 15:14:15 -05:00
2011-09-21 17:51:05 -05:00
/**
2011-09-21 23:16:35 -05:00
Cancels all operations in the HTTP client ' s operation queue that match the specified HTTP method and URL .
2011-09-21 17:51:05 -05:00
@ param method The HTTP method to match for the cancelled requests , such as ` GET ` , ` POST ` , ` PUT ` , or ` DELETE ` .
@ param url The URL to match for the cancelled requests .
*/
- ( void ) cancelHTTPOperationsWithMethod : ( NSString * ) method andURL : ( NSURL * ) url ;
2011-08-14 20:19:59 -05:00
2011-09-18 15:06:29 -05:00
///---------------------------
/// @name Making HTTP Requests
///---------------------------
2011-09-21 23:16:35 -05:00
/**
Creates an ` AFHTTPRequestOperation ` with a ` GET ` request , and enqueues it to the HTTP client ' s operation queue .
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
@ param parameters The parameters to be encoded and appended as the query string for the request URL .
2011-11-11 11:28:05 -06:00
@ param 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 .
@ param failure A block object to be executed when the request operation finishes unsuccessfully , or that finishes successfully , but encountered an error while parsing the resonse data . This block has no return value and takes two arguments : , the created request operation and the ` NSError ` object describing the network or parsing error that occurred .
2011-09-26 14:46:46 -05:00
2011-11-10 10:26:58 -06:00
@ see HTTPRequestOperationWithRequest : success : failure
2011-09-21 23:16:35 -05:00
*/
2011-09-21 14:00:05 -05:00
- ( void ) getPath : ( NSString * ) path
parameters : ( NSDictionary * ) parameters
2011-10-24 13:08:58 -05:00
success : ( void ( ^ ) ( AFHTTPRequestOperation * operation , id responseObject ) ) success
failure : ( void ( ^ ) ( AFHTTPRequestOperation * operation , NSError * error ) ) failure ;
2011-06-01 11:51:53 -05:00
2011-09-21 23:16:35 -05:00
/**
Creates an ` AFHTTPRequestOperation ` with a ` POST ` request , and enqueues it to the HTTP client ' s operation queue .
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
@ param parameters The parameters to be encoded and set in the request HTTP body .
2011-11-11 11:28:05 -06:00
@ param 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 .
@ param failure A block object to be executed when the request operation finishes unsuccessfully , or that finishes successfully , but encountered an error while parsing the resonse data . This block has no return value and takes two arguments : , the created request operation and the ` NSError ` object describing the network or parsing error that occurred .
2011-09-26 14:46:46 -05:00
2011-11-10 10:26:58 -06:00
@ see HTTPRequestOperationWithRequest : success : failure
2011-09-21 23:16:35 -05:00
*/
2011-08-05 10:58:37 -05:00
- ( void ) postPath : ( NSString * ) path
parameters : ( NSDictionary * ) parameters
2011-10-24 13:08:58 -05:00
success : ( void ( ^ ) ( AFHTTPRequestOperation * operation , id responseObject ) ) success
failure : ( void ( ^ ) ( AFHTTPRequestOperation * operation , NSError * error ) ) failure ;
2011-08-05 10:58:37 -05:00
2011-09-21 23:16:35 -05:00
/**
Creates an ` AFHTTPRequestOperation ` with a ` PUT ` request , and enqueues it to the HTTP client ' s operation queue .
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
@ param parameters The parameters to be encoded and set in the request HTTP body .
2011-11-11 11:28:05 -06:00
@ param 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 .
@ param failure A block object to be executed when the request operation finishes unsuccessfully , or that finishes successfully , but encountered an error while parsing the resonse data . This block has no return value and takes two arguments : , the created request operation and the ` NSError ` object describing the network or parsing error that occurred .
2011-09-26 14:46:46 -05:00
2011-11-10 10:26:58 -06:00
@ see HTTPRequestOperationWithRequest : success : failure
2011-09-21 23:16:35 -05:00
*/
2011-08-05 10:58:37 -05:00
- ( void ) putPath : ( NSString * ) path
parameters : ( NSDictionary * ) parameters
2011-10-24 13:08:58 -05:00
success : ( void ( ^ ) ( AFHTTPRequestOperation * operation , id responseObject ) ) success
failure : ( void ( ^ ) ( AFHTTPRequestOperation * operation , NSError * error ) ) failure ;
2011-06-01 11:51:53 -05:00
2011-09-21 23:16:35 -05:00
/**
Creates an ` AFHTTPRequestOperation ` with a ` DELETE ` request , and enqueues it to the HTTP client ' s operation queue .
@ param path The path to be appended to the HTTP client ' s base URL and used as the request URL .
@ param parameters The parameters to be encoded and set in the request HTTP body .
2011-11-11 11:28:05 -06:00
@ param 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 .
@ param failure A block object to be executed when the request operation finishes unsuccessfully , or that finishes successfully , but encountered an error while parsing the resonse data . This block has no return value and takes two arguments : , the created request operation and the ` NSError ` object describing the network or parsing error that occurred .
2011-09-26 14:46:46 -05:00
2011-11-10 10:26:58 -06:00
@ see HTTPRequestOperationWithRequest : success : failure
2011-09-21 23:16:35 -05:00
*/
2011-08-05 10:58:37 -05:00
- ( void ) deletePath : ( NSString * ) path
parameters : ( NSDictionary * ) parameters
2011-10-24 13:08:58 -05:00
success : ( void ( ^ ) ( AFHTTPRequestOperation * operation , id responseObject ) ) success
failure : ( void ( ^ ) ( AFHTTPRequestOperation * operation , NSError * error ) ) failure ;
2011-06-01 11:51:53 -05:00
@ end
2011-09-21 14:00:05 -05:00
# pragma mark -
2011-09-21 23:16:35 -05:00
/**
2011-09-26 11:50:13 -05:00
The ` AFMultipartFormData ` protocol defines the methods supported by the parameter in the block argument of ` multipartFormRequestWithMethod : path : parameters : constructingBodyWithBlock : ` .
2011-10-11 16:47:59 -05:00
@ see ` AFHTTPClient - multipartFormRequestWithMethod : path : parameters : constructingBodyWithBlock : `
2011-09-21 23:16:35 -05:00
*/
2011-09-26 11:50:13 -05:00
@ protocol AFMultipartFormData
2011-09-21 23:16:35 -05:00
/**
Appends HTTP headers , followed by the encoded data and the multipart form boundary .
@ param headers The HTTP headers to be appended to the form data .
@ param body The data to be encoded and appended to the form data .
*/
2011-09-21 14:00:05 -05:00
- ( void ) appendPartWithHeaders : ( NSDictionary * ) headers body : ( NSData * ) body ;
2011-09-21 23:16:35 -05:00
/**
2011-09-26 11:50:13 -05:00
Appends the HTTP headers ` Content - Disposition : form - data ; name = # { name } " `, followed by the encoded data and the multipart form boundary.
2011-09-21 23:16:35 -05:00
@ param data The data to be encoded and appended to the form data .
2011-09-23 10:21:07 -05:00
@ param name The name to be associated with the specified data . This parameter must not be ` nil ` .
2011-09-21 23:16:35 -05:00
*/
2011-09-26 11:50:13 -05:00
- ( void ) appendPartWithFormData : ( NSData * ) data name : ( NSString * ) name ;
/**
2011-11-07 12:16:42 -06:00
Appends the HTTP header ` Content - Disposition : file ; filename = # { filename } ; name = # { name } " ` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary.
2011-09-26 11:50:13 -05:00
@ param data The data to be encoded and appended to the form data .
2011-11-07 12:16:42 -06:00
@ param name The name to be associated with the specified data . This parameter must not be ` nil ` .
2011-09-26 11:50:13 -05:00
@ param mimeType The MIME type of the specified data . ( For example , the MIME type for a JPEG image is image / jpeg . ) For a list of valid MIME types , see http : //www.iana.org/assignments/media-types/. This parameter must not be `nil`.
2011-11-11 11:35:07 -06:00
@ param filename The filename to be associated with the specified data . This parameter must not be ` nil ` .
2011-11-07 12:16:42 -06:00
*/
- ( void ) appendPartWithFileData : ( NSData * ) data name : ( NSString * ) name fileName : ( NSString * ) fileName mimeType : ( NSString * ) mimeType ;
/**
Appends the HTTP header ` Content - Disposition : file ; filename = # { generated filename } ; name = # { name } " ` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary.
@ param fileURL The URL corresponding to the file whose content will be appended to the form .
2011-09-26 11:50:13 -05:00
@ param name The name to be associated with the specified data . This parameter must not be ` nil ` .
2011-11-07 12:16:42 -06:00
@ param error If an error occurs , upon return contains an ` NSError ` object that describes the problem .
2011-09-26 11:50:13 -05:00
2011-11-10 11:56:58 -06:00
@ return ` YES ` if the file data was successfully appended , otherwise ` NO ` .
2011-11-09 12:05:53 -06:00
@ discussion The filename and MIME type for this data in the form will be automatically generated , using ` NSURLResponse ` ` - suggestedFilename ` and ` - MIMEType ` , respectively .
2011-09-26 11:50:13 -05:00
*/
2011-11-10 11:56:58 -06:00
- ( BOOL ) appendPartWithFileURL : ( NSURL * ) fileURL name : ( NSString * ) name error : ( NSError * * ) error ;
2011-09-21 23:16:35 -05:00
/**
Appends encoded data to the form data .
@ param data The data to be encoded and appended to the form data .
*/
2011-09-21 14:00:05 -05:00
- ( void ) appendData : ( NSData * ) data ;
2011-09-21 23:16:35 -05:00
/**
Appends a string to the form data .
@ param string The string to be encoded and appended to the form data .
*/
2011-09-21 14:00:05 -05:00
- ( void ) appendString : ( NSString * ) string ;
2011-11-11 11:28:05 -06:00
2011-09-21 14:00:05 -05:00
@ end
2011-10-05 12:36:45 -05:00