我可能相信我目前正在这样做,这是我的代码,诀窍是使用“基本 base64encodedmethod(用户名:密码)”设置“授权”的标题
//SETUP URL
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://YOURURLHERE"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:90.0];
//Get the username & password - then encode the values with Base64 (i googled for a library)
NSString *userAndPassword = [NSString stringWithFormat:@"%@:%@",userName,password];
NSString *encodedString = [userAndPassword base64EncodedString];
//Set the Authorization header which will now let your service calls pass basic authentication
[request addValue:[NSString stringWithFormat:@"Basic %@",encodedString] forHTTPHeaderField:@"Authorization"];
//Setup a queue and call the async request - remember to do items in your block on the
//main thread if it's for things like showing/hiding items as other threads will not run that code when you're expecting it
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
//your code block here
}];
我相信这回答了你的问题,现在我只需要找出如何删除该身份验证,以便在我为安全的合法网站构建它时注销用户。任何帮助将不胜感激