I am trying to set the header values for my restkit calls. However, these do not seem to work.
I want to set Content-Type
and Accept
headers to application/json
Any idea where the problem is?
Thanks!
RKObjectManager *objectManager = [RKObjectManager sharedManager];
[[objectManager client] setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[[objectManager client] setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
RKURL *URL = [RKURL URLWithBaseURL:[objectManager baseURL] resourcePath:@"/users/sign_in.json" queryParameters:params];
[objectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@?%@", [URL resourcePath], [URL query]] delegate:self];
I don't think it's too obvious, though it is in the documentation (and I haven't tried tbh) but on the object manager there is a serializationMIMEType
property. There's also a constant for JSON already defined, so your code would probably look like:
objectManager.serializationMIMEType = RKMIMETypeJSON;
According to the docs, application/json is the default for Accept anyway, but can be specified by the acceptMIMEType
property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With