我目前正在尝试发布到我的 heroku 服务器。在本地一切正常,但是如果我将 AFHttpSessionmanager 的 url 更改为 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 ?