我_users
在 Cloudant 的数据库中有用户列表。当我尝试通过 cookie 身份验证向/_session
API 端点发送 POST 请求进行身份验证时,如下所示:
NSString *urlString = @"https://username:password@username.cloudant.com/_session";
NSMutableURLRequest *parseRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
NSMutableDictionary *postDictionary = [[NSMutableDictionary alloc]init];
NSError *error;
[postDictionary setValue:@"userinDB" forKey:@"name"];
[postDictionary setValue:@"passowrdinDB" forKey:@"password"];
NSData *postBody = [NSJSONSerialization dataWithJSONObject:postDictionary options:NSJSONWritingPrettyPrinted error:&error];
[parseRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[parseRequest setHTTPMethod:@"POST"];
[parseRequest setHTTPBody:postBody];
[NSURLConnection sendAsynchronousRequest:parseRequest
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
NSLog(@"error:%@",connectionError);
}
else {
NSLog(@"response:%@",response);
}
}];
它抛出以下异常:
{"error":"bad_request","reason":"user accounts must have a username"}
谁能帮我吗?