【发布时间】:2013-01-07 11:01:13
【问题描述】:
我正在使用 restkit 构建一个应用程序来与我的网络服务通信。首先,我对此很陌生。我需要做的是将用户名和密码发布到我的 web 服务,以便 url 看起来像这样。
http://urllinkcompany.com/en/webservice/company-user/login/apikey/key12345678?email=test@test.be&pwd=testtest
当我发布此内容时,我会返回一个 json。这个 json 包含一个状态码。 status = 200 --> OK
Status = 404 --> NOT ok
现在我尝试发布一些内容并 NSLog 这个状态代码。
- (IBAction)login:(id)sender {
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Person class]];
[mapping addAttributeMappingsFromDictionary:@{
@"data.user.cu_email": @"cu_email",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:nil keyPath:nil statusCodes:nil];
NSString *baseUrl = @"http://urllinkcompany.com/en/webservice/company-user/login/apikey/key12345678?";
NSString *strUrl = [NSString stringWithFormat:@"%@email=%@&pwd=%@",baseUrl,_txtLogin.text,_txtPass.text];
NSURL *url = [NSURL URLWithString:strUrl];
NSLog(@"url is: %@",strUrl);
NSURLRequest *request = [NSURLRequest requestWithURL:url];
RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"data result is %@", [result valueForKeyPath:@"data.status"]);
} failure:nil];
}
但是我收到了这个错误。
E restkit.network:RKObjectRequestOperation.m:285 Object request failed: Underlying HTTP request operation failed with error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x1ed57c50 {NSUnderlyingError=0x20161e70 "bad URL", NSLocalizedDescription=bad URL}
2013-01-07 11:48:51.407 Offitel2[22086:907] I restkit.network:RKHTTPRequestOperation.m:152 GET '(null)'
2013-01-07 11:48:51.408 Offitel2[22086:907] E restkit.network:RKHTTPRequestOperation.m:173 GET '(null)' (0) [0.0010 s]: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x1ed57c50 {NSUnderlyingError=0x20161e70 "bad URL", NSLocalizedDescription=bad URL}
有人可以帮我解决这个问题吗?
亲切的问候
【问题讨论】:
-
我使用 RKObjectManager 编辑了我的答案。有帮助吗?
-
不完全是,但它帮助我找到了正确的答案!所以谢谢!
标签: objective-c ios web-services post restkit