我正在尝试使用 AfNetworking AfHttpClient 登录谷歌阅读器,但我收到了这个错误,我似乎无法弄清楚。
下面是我的 AFNetworking 子类:
// main url endpoints
#define GOOGLE_ACCOUNTS_BASE_URL @"https://www.google.com/accounts/"
@implementation ADPGoogleLoginClient
+ (ADPGoogleLoginClient *)sharedClient {
static ADPGoogleLoginClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[ADPGoogleLoginClient alloc] initWithBaseURL:[NSURL URLWithString:GOOGLE_ACCOUNTS_BASE_URL]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}
[self registerHTTPOperationClass:[AFXMLRequestOperation class]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Content-type" value:@"text/plain"];
[self setDefaultHeader:@"Accept" value:@"text/plain"];
return self;
}
@end
然后我尝试使用以下代码形成请求:
//set up request params
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"googlereader-ios-client", @"client",
[keychainCredentials objectForKey:(__bridge id)kSecAttrAccount], @"Email",
[keychainCredentials objectForKey:(__bridge id)kSecValueData], @"Passwd",
@"reader", @"service",
@"ipad", @"source", nil];
//make requests
[[ADPGoogleLoginClient sharedClient] getPath:@"ClientLogin"
parameters:params
success:^(AFHTTPRequestOperation *operation , id responseObject)
{
//parse out token and store in keychain
NSString* responseString = [operation responseString];
NSString* authToken = [[[responseString componentsSeparatedByString:@"\n"] objectAtIndex:2]
stringByReplacingOccurrencesOfString:@"Auth=" withString:@""];
keychainToken = [[KeychainItemWrapper alloc] initWithIdentifier:@"GReaderToken" accessGroup:nil];
[keychainToken setObject:authToken forKey:(__bridge id)kSecValueData];
loginSuccess();
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"There was an error logging into Reader - %@", [error localizedDescription]);
loginFailure(error);
}];
我将默认标题设置为
[self setDefaultHeader:@"Content-type" value:@"text/plain"];
[self setDefaultHeader:@"Accept" value:@"text/plain"];
所以我不确定为什么它仍然认为它正在期待 xml?