我正在尝试从 googletrends 下载文件。为此,我必须登录。我正在使用 NSURLConnection 所以我想我必须使用
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
我必须设置什么参数?即如何定义用户名和密码??
最佳答案
使用 NSURLCredential 用于传递用户名和密码:
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSURLCredential *credential = [NSURLCredential credentialWithUser:userName password:userPassword persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
关于iphone - 登录谷歌下载文件 - ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14661496/