POST
서버에 개체를 보내려고했지만 작동하지 않습니다. 이것이 내가하는 일이다. 참고로, 나는 MagicalRecords를 CoreData
에 사용하고 있습니다.RestKit - postObject 건너 뛰기 매개 변수
DBComments *comment = [DBComments MR_createEntity];
comment.body = @"This is body";
comment.subject = @"This is subject";
comment.commentable_id = [NSNumber numberWithInt:291110];
comment.send_email = [NSNumber numberWithBool:YES];
[[RKObjectManager sharedManager] postObject:comment path:URL_COMMENTS
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
KLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
KLog(@"fail");
}];
하지만 응답 다음 얻을 : 당신이 응답에서 볼 수 있듯이
E restkit.network:RKObjectRequestOperation.m:576 Object request failed: Underlying HTTP request operation failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x11b688c0 {NSLocalizedRecoverySuggestion={"error":"body is missing, commentable_id is missing"}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest: 0xc632e50> { URL: http://10.28.79.98:3002/comments }, NSErrorFailingURLKey=http://10.28.79.98:3002/comments, NSLocalizedDescription=Expected status code in (200-299), got 400, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xc23cf70> { URL: http://10.28.79.98:3002/comments } { status code: 400, headers {
"Cache-Control" = "no-cache";
Connection = "Keep-Alive";
"Content-Length" = 54;
"Content-Type" = "application/json";
Date = "Fri, 28 Mar 2014 07:45:01 GMT";
Server = "WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)";
"X-Request-Id" = c8b765e61a8d44020be26e9b3267096e;
"X-Runtime" = "0.010554";
"X-Ua-Compatible" = "IE=Edge";
} }}
, 값이 여기에
{"error":"body is missing, commentable_id is missing"}
내 매핑 구성 게시 됨되지 않는
[objectManager addRequestDescriptorsFromArray:@[
// Comments
[RKRequestDescriptor requestDescriptorWithMapping:[self commentsRequestMapping]
objectClass:[DBComments class]
rootKeyPath:@""
method:RKRequestMethodPOST],
]];
- (RKObjectMapping *)commentsRequestMapping {
RKObjectMapping *commentsRequestMapping = [RKObjectMapping requestMapping];
[commentsRequestMapping addAttributeMappingsFromDictionary:@{
@"body" : @"body",
@"commentable_id" : @"commentable_id",
@"commentable_type" : @"commentable_type",
@"created_at" : @"created_at",
@"id" : @"id",
@"lft" : @"lft",
@"parent_id" : @"parent_id",
@"rgt" : @"rgt",
@"subject" : @"subject",
@"title" : @"title",
@"updated_at" : @"updated_at",
@"user_id" : @"user_id",
@"send_email" : @"send_email",
}];
return commentsRequestMapping;
}
나는 한 번도 사용할 수 없었습니다. postObject
. 내가 놓친 게 있니? 도와주세요.
매핑에 대한 추적 로깅을 켭니다. Charles가 보낸 내용을 확인하십시오. 요청 기술자에 nil 키 경로를 사용해야합니까? – Wain
@Wain, 답장을 보내 주셔서 감사합니다. 'rootKeyPath : nil'을 설정하면 트릭을 수행했습니다. – Khawar