在 iOS 中,如何以编程方式访问受 .htaccess 或访问控制保护的密码保护站点。
使用 NSURLRequest,您可以从 URL 发出 GET 请求。但如果 URL 受到保护,您将如何发送用户名密码对。另外,如果使用标准 MD5 加密进行加密会怎样?
将如下内容添加到您的 HTTP 连接代理中:
-(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];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)