AFNetworking 2.0 - “unacceptable content-type: text/plain”

前端 未结 7 1792
深忆病人
深忆病人 2020-12-28 15:12

I\'m using AFNetworking 2.0 to read JSON from a service I\'m building (on localhost for now) in Node. Pretty normal stuff.

Node is sending JSON like so

7条回答
  •  粉色の甜心
    2020-12-28 15:42

    Updated Solution for Swift.

    If you are using AFNetworking in Swift. Then this solution might help you. It will accept most of the content types.

    let manager=AFHTTPRequestOperationManager()
    
                manager.responseSerializer = AFJSONResponseSerializer(readingOptions: NSJSONReadingOptions.AllowFragments) as AFJSONResponseSerializer
    
                manager.requestSerializer = AFJSONRequestSerializer() as AFJSONRequestSerializer
    
                manager.responseSerializer.acceptableContentTypes = NSSet(objects:"application/json", "text/html", "text/plain", "text/json", "text/javascript", "audio/wav") as Set
    

提交回复
热议问题