I am currently trying to POST to my heroku server. Everything works fine locally but if i change my url for the AFHttpSessionmanager to the heroku App, my App wont work anymore cause the post requests gets interpreted as a GET Request on the Heroku-Side ..
This is how i do the Post-request :
NSString * postPath = [NSString stringWithFormat:@"/freetextquestions/%ld/freetextanswers.json",(long)identifier];
[[AskMeClient sharedClient] POST:postPath parameters: [NSDictionary dictionaryWithObject:self.answerTextField.text forKey:@"text"]
success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"%@", responseObject);
[self dismissViewControllerAnimated:YES completion:nil];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@", error);
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Ooops ..." message:error.localizedDescription delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles: nil];
[alert show];
}];
This is my Client :
@implementation AskMeClient
+(instancetype)sharedClient {
static AskMeClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[AskMeClient alloc] initWithBaseURL:[NSURL URLWithString:AskMeAPIBaseURLString]];
_sharedClient.securityPolicy = [AFSecurityPolicy defaultPolicy];
_sharedClient.responseSerializer = [AFJSONResponseSerializer serializer];
_sharedClient.requestSerializer = [AFJSONRequestSerializer serializer];
[_sharedClient.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
});
return _sharedClient;
}
@end
and this is what heroku says :
2014-02-24T00:32:35.246169+00:00 heroku[router]: at=info method=GET path=/freetextquestions/3/freetextanswers host=topsecretapp.herokuapp.com request_id=b2876fdb-d4bf-403a-a05a-4539830f9f0e fwd="193.175.119.11" dyno=web.1 connect=9ms service=44ms status=404 bytes=351
I tried everything to eliminate this error but i cant get it to work .. Does anybody has an idea what i am doing wrong ? Or is this a Heroku-Error ?
I found a Solution for this. If i use the subdomain provided by heroku it seems that the HTTP-Method gets lost in some way, maybe caused by some forwardings or redirects. Now i am using a other domain that references on to my heroku-App and everything works fine.