AFNetworking 动态修改acceptableContentTypes 设置ContentType
2017-03-13 15:20
323 查看
AFJSONResponseSerializer+Serializer.h
AFJSONResponseSerializer+Serializer.m
#import <AFNetworking/AFNetworking.h> @interface AFJSONResponseSerializer (Serializer) @end
AFJSONResponseSerializer+Serializer.m
#import "AFJSONResponseSerializer+Serializer.h" #import <objc/runtime.h> @implementation AFJSONResponseSerializer (Serializer) +(void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Method ovr_initMethod = class_getInstanceMethod([self class], @selector(init)); Method swz_initMethod = class_getInstanceMethod([self class], @selector(swizzlingForSetSerializer_init)); method_exchangeImplementations(ovr_initMethod, swz_initMethod); }); } - (id) swizzlingForSetSerializer_init { id swz_self = [self swizzlingForSetSerializer_init]; if (swz_self && [swz_self isKindOfClass:[AFJSONResponseSerializer class]]) { //start tiny NSSet * contentSet = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/plain", @"text/html", nil]; [swz_self setValue:contentSet forKey:@"acceptableContentTypes"]; } else { NSLog(@"AFJSONResponseSerializer+Serializer kvc get AFJSONResponseSerializer error"); } // return swz_self; } @end
相关文章推荐
- iOS中,修改AFNetworking源文件可接收text/plain的方法"Request failed: unacceptable content-type: text/plain"
- ASP.NET中动态修改web.config中的设置项目(CS页代码)(转贴)
- ASP.NET程序中动态修改web.config中的设置项目(前台页面代码)
- eclipse3.6默认指向WebContent目录修改为webRoot 设置说明
- C#入门学习-----菜单应用(添加剂快捷方式、设置菜单项是否可用、修改菜单字体、创建级联菜单、级联菜单的动态合并)
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- [转贴]ASP.NET中动态修改web.config中的设置项目
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET程序中动态修改web.config中的设置项目(转)
- sts for mac 更改webcontent目录clipse默认指向WebContent目录修改为webRoot 设置说明
- JS+style实现动态设置图片高宽 升级 按比例缩小图片高宽 (9月24日修改)
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- 动态修改log4net设置
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- 动态修改log4net的输出设置: HttpResponse
- eclipse默认指向WebContent目录修改为webRoot 设置说明
- 动态设置ODBC数据源(修改及新建)