AFNetworking AFHTTPClient Various Content Types for Success and Fail

I am trying to access a web service through a subclass of AFHTTPClient which has a complication

If the request succeeds, the content is returned as JSON. If for some reason this fails, the error from the server is returned in XML format.

At the moment, the only way to understand that I can handle this is not to try to use specific XML / JSON RequestOperations and cleanly process everything as a simple HTTP request, and then try to independently analyze it yourself, depending on what the answer looks like .

Unfortunately, I do not control the web service, or I would make sure that it is all JSON.

Does anyone have any better suggestions for this?

[EDIT]

I suppose one way to make it a little cleaner would be to create a new subclass of AFHTTPRequestOperation that would process the determination of the type of content inside, and then pass either processed JSON or a GDataXML object depending on what was returned from the server.

thank

+5
source share
1 answer

This may not be the cleanest or optimal solution, but you can check with your existing JSON library that the answer is really valid JSON. If so, continue as usual; if this is not the case, treat it with a manual demountable solution.

0
source

All Articles