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

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

问题描述

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

How can you, in iOS, programmatically 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];
        }
}

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

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