Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST data to API (Django #24

Open
alexvenom opened this issue Apr 1, 2014 · 1 comment
Open

POST data to API (Django #24

alexvenom opened this issue Apr 1, 2014 · 1 comment

Comments

@alexvenom
Copy link

For some reason, when using RNCachingURLProtocol together with AFNetworking, all my POST requests (JSON) to the API by AFNetworking stopped working. Took me a while to find out that RNCachingURLProtocol was interfering with it at some point.
Once I removed RNCachingURLProtocol, the API started working again.
All my POST requests were getting to the API as GET requests.

This is the code I was using:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] init];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];

[manager POST:serverURL parameters:parametersDict success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];

@rnapier
Copy link
Owner

rnapier commented Apr 24, 2014

RNCachingURLProtocol explicitly does not cache POST requests (or anything but GET requests). It's sample code to demonstrate how to build your own NSURLProtocol. It is typically configured by rewriting the parts that you want changed.

That said, this would not be a bad pull request. You just need to check that HTTPMethod is GET in canInitWithRequest: and return NO if it isn't. That would be a reasonable default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants