How can I deal with AFJSONRequestOperation 's response when my service return text/html?

StackOverflow https://stackoverflow.com/questions/8814306

  •  26-10-2019
  •  | 
  •  

سؤال

I'm new to AFNetWorkingk and my question is when I use AFJSONRequestOperation,my service returned a text/html result! Any one can give me some suggestions?Or other methord to implement this?

هل كانت مفيدة؟

المحلول

Just add text/html to the acceptableContentTypes like this:

[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

This is definitely a better option than the one below as you don't need to alter AFJSONRequestOperation.m

نصائح أخرى

Go to AFJSONRequestOperation.m

Add text/html

+ (NSSet *)defaultAcceptableContentTypes {
    return [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
}

Just a shot in the dark, but try setting the Accept header to application/json for the NSURLRequest, or if that doesn't work, add a .json to the end of the URL.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top