¿Por qué RestKit está cambiando mi tipo de contenido de respuesta?
En resumen: intento obtener datos del servidor con elcontent-type
del encabezado de solicitud http establecido como@"text/html
.. pero por alguna razón RestKit cambia eso aapplication/JSON
Explicación: Si tuviera que hacer esta solicitud usando soloRed de redes... las cosas funcionan a la perfección ... así es como se ve mi código de red de redes:
AFHTTPClient *client = [AFHTTPClient alloc] initWithBaseURL:
[NSURL URLWithString:kApiBaseUrl]];
singleton.parameterEncoding = AFJSONParameterEncoding;
[singleton setDefaultHeader:@"Accept" value:@"text/html"];
[client getPath:getPath parameters:nil success:successCallback failure:failureCallback];
Si yo uso esoexactamente el mismo cliente y adjuntarlo a
MyClient *client = [MyClient getSingleton]; //MyClient is instantiated as above
self.objectManager = [[RKObjectManager alloc] initWithHTTPClient:client];
self.objectManager.managedObjectStore = self.managedObjectStore;
// this should have already been done by my client, but putting
// it here just to be sure
[self.objectManager setAcceptHeaderWithMIMEType:@"text/html"];
[[RKObjectManager sharedManager] getObjectsAtPath:kGradesPath
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
// handle success
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
// handle failure
}];
el error que recibo es:
restkit.network:RKObjectRequestOperation.m:576 Object request failed:
Underlying HTTP request operation failed with error: Error
Domain=org.restkit.RestKit.ErrorDomain Code=-1016 "Expected content type {(
"application/x-www-form-urlencoded",
"application/json"
)}, got text/html" UserInfo=0x8f7acd0
cavando en el tema .. puse un punto de ruptura enmanagedObjectRequestOperationWithRequest, luego revisé eltipos de contenidos aceptables deHTTPRequestOperation
creado, y es nulo! Por lo tanto, asumo que RestKit solo pone sus propios tipos de contenido aceptables predeterminados. Simplemente no sé dónde y cómo evitarlo. ideas?
PD. No tengo control sobre el servidor, así que no puedo cambiarlo.content-type
encabezado aapplication/JSON
Actualizar:
Resulta que enRKObjectRequestOperation.m obtiene elmime-type
desde[RKMIMETypeSerialization registeredMIMETypes];
(línea 354) .. y así enRKMIMETypeSerialization.hAhí está el método:
/**
Registers the given serialization class to handle content for the given MIME Type identifier.
MIME Types may be given as either a string or as a regular expression that matches the MIME Types for which the given serialization should handle. Serializations are searched in the reverse order of their registration. If a registration is made for an already registered MIME Type, the new registration will take precedence.
@param serializationClass The class conforming to the RKSerialization protocol to be registered as handling the given MIME Type.
@param MIMETypeStringOrRegularExpression A string or regular expression specifying the MIME Type(s) that given serialization implementation is to be registered as handling.
*/
+ (void)registerClass:(Class<RKSerialization>)serializationClass forMIMEType:(id)MIMETypeStringOrRegularExpression;
¿Cómo uso esto para registrar untext/html
¿tipo de contenido?