Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set header values in Restkit

Tags:

ios

restkit

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];
like image 951
Karan Avatar asked Dec 15 '22 22:12

Karan


1 Answers

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.

like image 128
brindy Avatar answered Dec 29 '22 22:12

brindy