How to read a simple string from a POST request in AFNetworking (No JSON)
You can tell the AFHTTPRequestOperationManager
or AFHTTPSessionManager
how to handle the response, e.g. before calling POST
, you can do the following:
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
Then in your success
block, you can convert the NSData
to a string:
NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
Having said that, you might want to contemplate converting your web service to return JSON response, as it's far easier to parse that way (and differentiate between a valid response and some server error).
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
you can get response description details like below
NSLog(@"JSON: %@", [responseObject description]);
Much better way would be subclassing AFHTTPResponseSerializer and overriding there
func responseObject(for response: URLResponse?, data: Data?, error: NSErrorPointer) -> Any?
There you can parse response, cast to type you need and return.