← Back to Upcase

How to properly do a post from my ios app?


(charlieanna) #1

When I do a post request from my mobile app to the rails server while using NSURLRequestUseProtocolCachePolicy I don’t get the params, only the controller name and the action name. But when I use NSURLRequestReloadIgnoringCacheData I properly get all the params printed on the console by using puts params.

This is how I am doing the post in my iOS application.

    NSURL *aUrl = [NSURL URLWithString:@"http://developer.idlecampus.com/devices"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
                                                           cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                       timeoutInterval:60.0];
    
    
    
    [request setHTTPMethod:@"POST"];
    NSString *postString = [NSString stringWithFormat:@"registration_id=%@&device_identifier=%@&device_type=IOS",registration_Id,device_identifier];
   [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request
                                                                 delegate:self];

(Gordon Fontenot) #2

So is the problem that you aren’t seeing the params in your console on the rails end of things? Or that you aren’t getting the right response from the server on the iOS side?


(charlieanna) #3

I am not seeing the full params in the rails console. But the strange thing is, when I do this call to my local rails app on production I get the full params but when I do same thing to my deployed app on AWS server which is in production I don’t see the params.


(Gordon Fontenot) #4

The rails side of this is a bit out of my wheelhouse, but is it possible that the deployed app isn’t providing cache expiration information for the requests? It looks like there is some odd behavior with NSURLConnection when hitting a server that isn’t providing cache expiration information while using the default cache behavior of NSURLRequestUseProtocolCachePolicy. Essentially, Apple has implemented the default timeout as somewhere between 6 and 24 hours, and will hit the local cache instead of your server if the cache is detected. That would explain why using NSURLRequestReloadIgnoringCacheData would be sending the expected params to the server.

You can read more in depth about this in this blog post