iphone - 登录谷歌下载文件 - ios

标签 iphone ios objective-c nsurlconnection

我正在尝试从 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];
}

请查看本教程:Handling URL Authentication challenges

关于iphone - 登录谷歌下载文件 - ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14661496/

相关文章:

jquery - 如何避免在 iPhone 应用程序上下拉屏幕

iphone - 复制 xcode 项目以创建精简版应用程序后,FB 登录失败

iphone - 如何创建一个可以从不同 View Controller 访问的 NSMutable 数组

ios - 如果条件为真,如何转移到特定的 Storyboard?

iphone - 具有键盘按钮样式的 UIButton

iphone - AlertView 应该自行消失

iphone - 使用 CCSpriteFrameCache 为动画 Sprite 添加标签

iphone - 如何对 UILabel 的 textColor 进行动画处理?

ios - 个人资料图片未从 Facebook 图形 api 获取

ios - 如何以编程方式获取 "version code"和 "model code"