在iPhone SDK中,您将如何以编程方式将用户名/密码传递到安全站点 [英] In the iPhone SDK, how would you programatically pass a username / password to a secure site

查看:107
本文介绍了在iPhone SDK中,您将如何以编程方式将用户名/密码传递到安全站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在iPhone SDK中以编程方式访问受.htaccess或访问控制保护的受密码保护的网站。

How can you, in the iPhone SDK, programatically access a password protected site that has been protected by .htaccess or access control.

使用NSURLRequest,您可以制作来自URL的GET请求。但是,如果URL受到保护,您将如何发送用户名密码对。此外,如果使用标准MD5加密进行加密,该怎么办呢?

Using NSURLRequest, you can make a GET request from a URL. But if the URL is protected how would you send the username password pair. Also, what if it's encrypted with standard MD5 encryption.

推荐答案

将这样的内容添加到HTTPConnectionDelegate:

Add something like this to your HTTPConnectionDelegate:

-(void)connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
        if ([challenge previousFailureCount] == 0) {
                NSURLCredential *newCredential;
                newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
                [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        } else {
                [[challenge sender] cancelAuthenticationChallenge:challenge];
        }
}

这篇关于在iPhone SDK中,您将如何以编程方式将用户名/密码传递到安全站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆