AFNetworking 2 Response Error (Content type: text/html and not JSON)

前端 未结 2 685
梦如初夏
梦如初夏 2021-01-13 06:40

After trying nearly every response on the subject, I\'ve come up without a working answer to my problem.

The problem: So I\'ve implemented the uploading portion of m

相关标签:
2条回答
  • 2021-01-13 07:19

    Got it! So, turns out, unknowingly, although my API was returning valid JSON, matter examining the header response logged on the Xcode side of things (thru NSLog(@"Error: %@", error);), it was actually returning text/HTML because it wasn't actually hitting the correct file, it was getting re-routed by a header somewhere. After explicitly stating the API path to be /API/index.php and not just /API, it started returning the valid JSON! Next, after making sure the response was properly JSON serialized (using requestManager.responseSerializer = [AFJSONResponseSerializer serializer];), the app worked!

    Hopefully this helps someone who was having the same issue :)

    0 讨论(0)
  • 2021-01-13 07:41

    You can set the AFHTTPSessionManager to accept any MIME Type:

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    0 讨论(0)
提交回复
热议问题