The documentation for AFNetworking notes that you should create subclass of AFHTTPClient and use it as a singleton per web-service.
If I have 2 endpoints at http://www.example.com, one that allows for ‘application/json’ in HTTP_ACCEPT and another that needs text/html, what parameter would I configure in my singleton AFHTTPClient class so that it configures the correct HTTP_ACCEPT value?
Implementation details:
@interface MyAFHTTPClient : AFHTTPClient
+ (MyAFHTTPClient *)sharedClient;
@end
[[MyAFHTTPClient sharedClient] getPath:@"endPoint_json"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}]
At a later time, I need to invoke the html endpoint:
[[MyAFHTTPClient sharedClient] getPath:@"endPoint_html"
parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}]
It seems that both of these calls cause "HTTP_ACCEPT"=>"application/json" when the server receives the request.
getPath:...and all of those convenience methods construct a request withrequestWithMethod:path:parameters:, and then pass that intoHTTPRequestOperationWithRequest:success:failure:, which is then enqueued into an operation queue.If you need to do a one-off request for HTML or the like, do these steps manually rather than using the convenience method: create the request, set the
Accept(HTTP_ACCEPT) is not an HTTP header) header totext/html, and then create and enqueue the operation.