尝试使用邮差api,但遇到授权问题。
引用他们的网站:
认证 Postmates需要通过HTTP头进行身份验证。您的API键应该包含在用户名中。密码应保留为空。 实际使用的标题将是一个base64 64编码的字符串,如下所示:
Basic Y2YyZjJkNmQtYTMxNC00NGE4LWI2MDAtNTA1M2MwYWYzMTY1Og==
我试过像这样使用AFNetworking
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"(my postmates key)" password:@"" persistence:NSURLCredentialPersistenceNone];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"GET" URLString:@"https://api.postmates.com/v1/delivery_zones" parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCredential:credential];
[operation setResponseSerializer:[AFJSONResponseSerializer alloc]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", error);
}];
[manager.operationQueue addOperation:operation]; 我得到的错误信息是
Incorrect NSStringEncoding value 0x0000 detected. Assuming NSASCIIStringEncoding. Will stop this compatiblity mapping behavior in the near future.
Success: {
code = "invalid_authorization_header";
kind = error;
message = "Your API key was not formatted properly";
}发布于 2016-05-01 00:42:49
与其创建凭据,不如尝试:
[request setValue:@"Basic Y2YyZjJkNmQtYTMxNC00NGE4LWI2MDAtNTA1M2MwYWYzMTY1Og==" forHTTPHeaderField:@"Authorization"];https://stackoverflow.com/questions/36961734
复制相似问题