저는 RestKit을 처음 사용하고 시스템에 로그인 할 때 POST 요청을 사용하려고합니다. 내가 RestKit 버전 0.20.3을 사용하고 있는데 이것은 내가 한 방법입니다RestKit에서 POST를 사용하여 로그인하면 404 오류가 발생합니다.
- (IBAction)login:(id)sender {
NSString *email = [self.emailTextField text];
NSString *password = [self.passwordTextField text];
NSURL *url = [[NSURL alloc] initWithString:@"http://myhost.com/api.php"];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:url];
NSDictionary *tmp = @{@"rquest":@"user",
@"tag":@"login",
@"email":email,
@"password":password};
[manager postObject:tmp path:@"" parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSDictionary *result = [mappingResult dictionary];
if([[result objectForKey:@"success"] isEqualToNumber:[NSNumber numberWithInt:1]]){
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setBool:YES forKey:@"isLoggedIn"];
// set user details...
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Hit error: %@", error);
}];
}
정말 객체에 응답을 매핑 할 필요가 없기 때문에 당신이 볼 수 있듯이, 나는 응답 데이터에 액세스하려고 NSDictionary
. 나는이 문제가 있는지 확실하지 않습니다,하지만 위의 코드를 실행하려고하면, 나는 오류 얻을 : 정말 내가 여기서 뭘 잘못했는지 모를
013-10-06 11:24:51.897 Eateries[1182:454b] E restkit.network:RKResponseMapperOperation.m:304 Failed to parse response data: Loaded an unprocessable response (404) with content type 'application/json'
2013-10-06 11:24:51.902 Eateries[1182:1003] E restkit.network:RKObjectRequestOperation.m:243 POST 'http://myhost.com/api.php' (404 Not Found/0 objects) [request=0.1479s mapping=0.0000s total=0.1648s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (404) with content type 'application/json'" UserInfo=0x8ee81e0 {NSErrorFailingURLKey=http://myhost.com/api.php, NSUnderlyingError=0x8ef4ea0 "The operation couldn’t be completed. (Cocoa error 3840.)", NSLocalizedDescription=Loaded an unprocessable response (404) with content type 'application/json'}
2013-10-06 11:24:51.978 Eateries[1182:a0b] Hit error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (404) with content type 'application/json'" UserInfo=0x8ee81e0 {NSErrorFailingURLKey=http://myhost.com/api.php, NSUnderlyingError=0x8ef4ea0 "The operation couldn’t be completed. (Cocoa error 3840.)", NSLocalizedDescription=Loaded an unprocessable response (404) with content type 'application/json'}
정말 혼란 스러워요을 . 친절히 제안 해 주시면 알려 주시기 바랍니다. 고맙습니다.
P.s : 내 개인 용도로만 호스트 이름을 변경했지만 다른 플랫폼에서 서버를 테스트하려고하면 서버가 실제로 요청에 응답합니다.
문제가있는 곳에서 고맙습니다. –