I need to send ordinary HTTP request (GET) and answer will in text/html.
How can I send this response using AFNetworkin 2 ?
Now I'm trying to use
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://example.com"]];
[self HTTPRequestOperationWithRequest:request
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
And was frustrates – it do nothing. When debugging, nor success nor fail clause have been triggered.
Also I tried to use GET:parameters:success:failure: method, but in response I see this error:
Error: Error Domain=AFNetworkingErrorDomain Code=-1016 "Request
failed: unacceptable content-type: text/html"
Please, anybody can explain me what are wrong and what is the correct way to send request (if I will get response as text/html)?
Regards, Alex.
Best Answer
You said in your comment, in response to the suggestion to use the
AFHTTPRequestOperationManager
:You can remedy that with a
AFHTTPResponseSerializer
:You can also use
AFHTTPRequestOperation
:Ideally, though, it's advisable to write server code that returns JSON (or XML), as that's much easier for an app to consume and parse.