您可以通过继承 RKObjectManager 并更改 requestWithObject:method:path:parameters: 在子类管理器中的实现来更改单个请求的 serializationMIMEType。
发送请求:
SubclassedObjectManager *manager = ...
[manager putObject:nil
path:pathString
parameters:parameters
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}
];
修改 PUT 方法请求的 MIMEType:
- (NSMutableURLRequest *)requestWithObject:(id)object method:(RKRequestMethod)method path:(NSString *)path parameters:(NSDictionary *)parameters
{
NSMutableURLRequest *request = [super requestWithObject:object method:method path:path parameters:parameters];
if (method&RKRequestMethodPUT) {
NSError *error = nil;
NSData *serializedJSON = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
[request setValue:RKMIMETypeJSON forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:serializedJSON];
}
return request;
}