我正在使用RestKit,我试图发布一个查询参数(token=<token>
形式的身份验证令牌)对象,但我不知道如何让它工作。下面是我在做什么...RestKit postObject与查询参数
首先,我添加请求对象映射到经理:
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];
当请求时,Location对象被序列化为JSON并放入请求正文。但是,不是将该令牌添加到查询字符串中,而是将其作为JSON添加到请求正文中。
例子:
request.body={"id":0,name="test","longitude":-0.1337,"latitude":51.50998,"token":"Z3JlZ2c6MTM2MDU2OTk2MDY2OTpMajkxd01acWxjcGg1dEpFVy9IaEcwNTcyMWJkSEpnTFRTQTI2eXNlN29VOVRTc1UwV1lEU0E9PQ=="}
任何帮助,不胜感激!
你有没有找到一个解决这个?我可以准确地复制你的问题。 –
这是一种语义,但是如果您打算发送带有请求的授权令牌,则它可能位于授权标头中。 – barndog