_users
Cloudantの DB にユーザーのリストがあります。/_session
以下のようにAPIエンドポイントにPOSTリクエストを送信するCookie認証で認証しようとすると:
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"}
誰でも私を助けることができますか?