2015-04-28 43 views
0

我一直在使用Restkit for GET,現在我試圖使用它來獲取錯誤。這裏是我的RESTKit我認爲的代碼是相當標準: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」的錯誤: enter image description here

我GOOGLE了它,但似乎所有線程都從一個談論CSRF令牌表單,在我的情況下是第三方IOS應用程序。我的RESTFul API由Laravel 5運行。任何想法將不勝感激。感謝您的關注。

+1

你有一個請求描述符?服務器期待什麼,它會得到什麼? – Wain

回答

1

在你的情況,你要映射的請求(不響應)的對象(事務),所以不是使用responseDescriptorWithMapping你應該使用這種方法:

+ (instancetype)requestDescriptorWithMapping:(RKMapping *)mapping objectClass:(Class)objectClass rootKeyPath:(NSString *)rootKeyPath method:(RKRequestMethod)method 
+0

我是否也需要requestMapping? – emersonku

+0

是的,如果你通過POST發送對象,你必須。 建議:爲避免再次重複映射,我建議您使用inverseMapping實用程序: requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[mappingTransaction inverseMapping] objectClass:[Transaction class] rootKeyPath:nil method:RKRequestMethodPOST]; –

+0

謝謝,剛剛嘗試,但仍然得到相同的錯誤.. – emersonku