我正在使用RestKit并尝试提交一个带有查询参数的对象(形式为
首先,我将请求对象映射添加到管理器中:
然后我发出请求:
当请求被发出时,位置对象会被序列化为JSON,并被放置在请求体中。然而,令牌并没有被添加到查询字符串中,而是以JSON格式被添加到请求体中。
示例:
token=<token>
中的身份验证令牌),但我无法弄清如何使其正常工作。这是我的操作步骤...首先,我将请求对象映射添加到管理器中:
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromDictionary:@{
@"id" : @"id",
@"name" : @"name",
@"latitude" : @"latitude",
@"longitude" : @"longitude"
}];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[Location class] rootKeyPath:nil];
[manager addRequestDescriptor:requestDescriptor];
然后我发出请求:
RKManagedObjectRequestOperation *operation = [RKObjectManager.sharedManager appropriateObjectRequestOperationWithObject:self method:RKRequestMethodPOST path:@"/api/v1/users/3/locations" parameters:@{@"token" : token}];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
Location * location = (Location*)mappingResult;
self.id = Location.id;
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
ALog(@"fail!");
}];
[RKObjectManager.sharedManager enqueueObjectRequestOperation:operation];
当请求被发出时,位置对象会被序列化为JSON,并被放置在请求体中。然而,令牌并没有被添加到查询字符串中,而是以JSON格式被添加到请求体中。
示例:
request.body={"id":0,name="test","longitude":-0.1337,"latitude":51.50998,"token":"Z3JlZ2c6MTM2MDU2OTk2MDY2OTpMajkxd01acWxjcGg1dEpFVy9IaEcwNTcyMWJkSEpnTFRTQTI2eXNlN29VOVRTc1UwV1lEU0E9PQ=="}
非常感谢您的帮助!