didReceiveAuthenticationChallenge يسبب exc_bad_access
-
22-09-2019 - |
سؤال
إذا لم يكن موقع الويب يتطلب المصادقة ، فإن الكود الخاص بي يعمل بشكل جيد ، إذا كان الأمر كذلك ، فإنه يخطئ مع exc_bad_access مباشرة بعد طباعة "بيانات الاعتماد". أنا لا أطلق أي شيء ، ويتم نسخ هذا الرمز مباشرة من الوثائق - أي فكرة عن الخطأ؟
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge previousFailureCount] == 0)
{
NSLog(@"received authentication challenge");
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:@"root"
password:@"rootpassword"
persistence:NSURLCredentialPersistenceForSession];
NSLog(@"credential created");
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
NSLog(@"responded to authentication challenge");
}
else
{
NSLog(@"previous authentication failure");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Authentication Failure"
message:@"Website did not accept the username and password."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
المحلول
اتضح أن الأمر يتعلق بهذه الطريقة الخاصة بمصادقة المواقع الخاصة - استبدال موقع الويب الذي أريد تسجيل الدخول إليه مع موقع ويب آخر ويعمل الرمز بشكل جيد.
(كنت أحاول كشافة البيانات من صفحة حالة Unraid ، لا تستخدم Donraid خادمًا فعليًا ولكن eMHTTP لذلك أفترض أن هذا له علاقة به)
نصائح أخرى
الشيء الوحيد الذي لا تتحكم فيه هو قيمة إرجاع [challenge sender]
. حاول طباعة وصفها للتأكد من أنها غير مكلمة.
لا تنتمي إلى StackOverflow