The pitfalls in the AFN parser, the AFN parser
The AFN framework is used to send network requests. It can automatically parse JSON data and send request with parameters.
The AFN framework can also monitor the current network status and support HTTPS requests. The classes used are AFNetworkReachabilityManager and AFSecurityPolicy.
Although AFN can send requests, there are many pitfalls in it,
1. to get the correct JSON data, you must: The network request is successful, the server must return JSON data, And You (AFN) can also parse the data, that is, the request you sent, the returned data type must be JSON data and end with JSON data. This is required because only the data types recognized by the parser include application/json, text/json, text/javascript.
2. AFN has three types of Resolvers. The default is the JSON parser and the omnipotent parser. It can't do anything because it returns all the data as binary data, you have to resolve it yourself.
3. The biggest headache is parsing XML data. AFN also has an XML parser, but it only returns a parser that has to be parsed by itself.
If you change the parser type, the returned data type will change. refer to the following:
1. JSON Parser: Return JSON parsed data. ------ JSON
2. XML Parser: NSXMLParser is returned ------ XML/the default is SAX parsing.
3. omnipotent Parser: returns NSData data. ----- JSON/XML/HTML/various files...
For file/image/Video/Webpage HTML, you can only select the omnipotent parser!