我正在尝试POST到我的heroku服务器。 一切都在本地工作正常,但如果我将我的AFHttpSessionmanager的网址更改为heroku应用程序,我的应用程序将不再工作,因为帖子请求被解释为Heroku端的GET请求..
这就是我做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];
}];
这是我的客户:
@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
这就是heroku所说的:
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
我尝试了一切来消除这个错误,但我无法让它工作.. 有没有人知道我做错了什么?或者这是Heroku-Error?
答案 0 :(得分:0)
我找到了解决方案。 如果我使用heroku提供的子域,似乎HTTP-Method以某种方式丢失,可能是由某些转发或重定向引起的。 现在我正在使用引用我的heroku-App的其他域名,一切正常。