Create a management singleton class to inherit Afhttpsessionmanager, encapsulate the data request method into the Post method
Urlsession
Substitution of URLConnection in Foundation
Support for network tasks running in the background
Pause/Stop/Restart network tasks, no longer require nsoperation encapsulation
Requests can use the same configuration container
Different session can use different private storage
Block and agent work simultaneously
Upload downloads directly from the file system
Nsurlsessionconfiguration
DEFAULTSESSIONCONFI-Cache/cookie/Certificate Global non-private, approximate to Nsurlconnection
Ephemeralsessionconfiguration-Cache/cookie/Certificate Global private but non-persistent
BACKGROUNDSESSIONCONFI-Suitable for applications being suspended or receiving remote notification
Some properties of nsurlsessionconfiguration
Httpadditionalheaders:http Protocol Header information
Allowcellularaccess/discretionary: The former runs the operator network/the latter is optimized for background network tasks (when a wifi/device is in good condition)
Timeoutintervalforrequest/timeoutintervalforresource: The former resets every time a new data arrives, which limits the length of the entire resource request
Httpmaximumconnectionperhost: Maximum number of concurrent connections for a host
Nsurlsessiontask
can send cancel/resume/suspend messages
Nsurlsessiondatatask return NSData
Nsurlsessiondownloadtask return file, download progress can be resumed
Nsurlsessionuploadtask Upload Nsdata/file/stream
Tasks are suspended by default, remember to send a resume message to a task
AFN Two-time package