在WebView中使用NTLM/Basic Auth。Objective-C/Android
我正在制作一个iOS应用程序,我正在使用UIWebView来显示一个站点,一切似乎都很正常 但是当我进入这个站点的一个页面,需要HTTP身份验证(Basic/NTLM Auth,HTTP)时,它就不能正常工作了 我正在阅读,发现了一个方法在WebView中使用NTLM/Basic Auth。Objective-C/Android,android,ios,objective-c,uiwebview,basic-authentication,Android,Ios,Objective C,Uiwebview,Basic Authentication,我正在制作一个iOS应用程序,我正在使用UIWebView来显示一个站点,一切似乎都很正常 但是当我进入这个站点的一个页面,需要HTTP身份验证(Basic/NTLM Auth,HTTP)时,它就不能正常工作了 我正在阅读,发现了一个方法didReceiveAuthenticationChallenge,该方法指示何时需要在页面中进行身份验证 我找到了苹果公司提供的一个例子(但它不适用于我) 我在Android上做了同样的测试,我发现我们可以使用这种方法(它对我有效): 我的问题是,在objec
didReceiveAuthenticationChallenge
,该方法指示何时需要在页面中进行身份验证
我找到了苹果公司提供的一个例子(但它不适用于我)
我在Android上做了同样的测试,我发现我们可以使用这种方法(它对我有效):
我的问题是,在objective-C中,HTTP身份验证(基本身份验证,HTTP)的正确方法是什么
我对同一个网站的两个应用程序(安卓和IOS)进行了测试,所以安卓应用程序工作正常,但IOS应用程序工作不正常
任何建议对我都是有用的
谢谢。这个问题就是这样。
-(void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential = [NSURLCredential credentialWithUser:[self preferencesName]
password:[self preferencesPassword]
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
// inform the user that the user name and password
// in the preferences are incorrect
[self showPreferencesCredentialsAreIncorrectPanel:self];
}
}
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
handler.proceed(username, password);
...
}