私はhudson URLアドレスからJSONを取得し、HTTP認証を使用して自分の(Mac OS X)アプリケーションを認証しようとしています。AFNetworkingでHTTP認証を使用してJSONを取得
私が使用している例を次に示します。
// AppDelegate.m
- (void) doSomething {
[[CommAPIClient sharedClient] getPath:@"/computer/api/json" parameters:nil
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Name: %@", [responseObject valueForKeyPath:@"totalExecutors"]);
} failure:nil];
}
// CommAPIClient.m
+ (CommAPIClient *) sharedClient {
static CommAPIClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
AppDelegate *appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
_sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString: [appDelegate.hudsonTextField stringValue]]];
});
return _sharedClient;
}
- (id) initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (self){
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
AppDelegate *appDelegate = (AppDelegate *)[[NSApplication sharedApplication] delegate];
userName = [appDelegate.userTextField stringValue];
password = [appDelegate.passwdTextField stringValue];
[self setAuthorizationHeaderWithUsername:userName password:password];
[self setDefaultHeader:@"Accept" value:@"application/json"];
}
return self;
}
を、私は私のドロップダウンリストに表示するコンピュータのリストを取得したいのですが、この2行が一緒に動作しません: [自己setAuthorizationHeaderWithUsername:ユーザー名パスワード:パスワードを]; [self setDefaultHeader:@ "受け入れる"値:@ "application/json"];私は、キーを取得しようとするので、私はちょうど最初の行、私のautheticationの作品を使用しますが、私はそのエラーを受け取った場合
:二行目を使用している場合
2012-02-03 02:43:57.542 HudsonSlave[7523:707] An uncaught exception was raised
2012-02-03 02:43:57.542 HudsonSlave[7523:707] [<NSConcreteData 0x100850000> valueForUndefinedKey:]: this class is not key value coding-compliant for the key totalExecutors.
2012-02-03 02:43:57.623 HudsonSlave[7523:707] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSConcreteData 0x100850000> valueForUndefinedKey:]: this class is not key value coding-compliant for the key totalExecutors.'
、私の認証がエラー403を返します。
誰でも問題を解決できますか?
ありがとう、ご迷惑をおかけして申し訳ありません。
チアゴ
両方の行を使用するとどうなりますか? – mattt
@mattt、エラーは私にコンテンツタイプが見つからないと言ったので、私は3行目を追加しました: [self setDefaultHeader:@ "Content-Type" value:@ "application/json"]; とエラーである: エラードメイン= com.alamofire.networking.errorコード= -1016「期待するコンテンツタイプ{( "テキスト/ javascriptの"、 "アプリケーション/ JSON"、 "テキスト/ JSON" )}、アプリケーション/ JavaScriptを持っ」のUserInfo = 0x100513190 {NSLocalizedDescription =期待されるコンテンツ・タイプ{( "テキスト/ javascriptの"、 "アプリケーション/ JSON"、 "テキスト/ JSON" )}、アプリケーション/ JavaScriptを得、NSErrorFailingURLKey = http://hudson.concretecorp.com.br/computer/api/json} – unnamedd