我已成功使用Restkit for GET,现在我尝试将其用于POST并获取错误。这是我的RESTKit的代码,我认为这是非常标准的:
RKObjectMapping *mappingTransaction = [RKObjectMapping mappingForClass:[Transaction class]];
NSDictionary *mappingTransactionDict = @{
@"final_price" : @"finalPrice",
@"discount" : @"discount",
@"customer_fk" : @"customerID",
@"typeofpayment_fk" : @"typeOfPaymentID",
@"shop_fk" : @"shopID",
@"systemuser_fk" : @"systemUserID",
@"company_fk" : @"companyID",
@"created_at" : @"creationDate",
@"updated_at" : @"updateDate"
};
[mappingTransaction addAttributeMappingsFromDictionary:mappingTransactionDict];
RKResponseDescriptor *transactionDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:mappingTransaction
method:RKRequestMethodPOST
pathPattern:@"/revenue/add/transaction"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:transactionDescriptor];
[[RKObjectManager sharedManager] postObject:(Transaction *)transactionRecord
path:@"/revenue/add/transaction"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
//self.typeOfPaymentArray = mappingResult.array;
}
failure:^(RKObjectRequestOperation *operation, NSError *error){
NSLog(@"Transaction insert failed': %@", error);
}];
然后出现“TokenMismatchException”错误:
我google了它,但似乎所有线程都在谈论表格中的CSRF令牌,在我的情况下是第三方IOS应用程序。我的RESTFul API由Laravel 5运行。任何想法都将受到赞赏。谢谢你的关注。
答案 0 :(得分:1)
在您的情况下,您希望在请求中(而不是在响应中)映射对象(事务),因此您应该使用此方法而不是使用def resolve(self, endCoord):
:
responseDescriptorWithMapping