NSURLErrorDomain-Fehler -1012

Muss ich parse eine xml-Datei in einem Passwort geschützten URL ich habe versucht, die folgenden

NSURLCredential *credential = [NSURLCredential credentialWithUser:@"admin"  password:@"123456" persistence:NSURLCredentialPersistenceForSession];
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                         initWithHost:@"xyz.com"
                                         port:80
                                         protocol:@"http"
                                         realm:nil
                                         authenticationMethod:NSURLAuthenticationMethodDefault];  
[[NSURLCredentialStorage sharedCredentialStorage] setCredential:credential
                                             forProtectionSpace:protectionSpace];    
url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSURLResponse *response;
NSError *error;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: &response error: &error];   
 NSString *dataStr=[[NSString alloc]initWithData:returnData encoding:NSUTF8StringEncoding]; 
 NSLog(@"data == %@\n error in connecting == %@",dataStr,error);

Bekam ich folgende Antwort

data == <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<p>Additionally, a 401 Authorization Required
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

Fehler bei der Verbindung == Error Domain=NSURLErrorDomain Code=-1012 "Der Vorgang konnte nicht abgeschlossen werden. (NSURLErrorDomain error -1012.)" UserInfo=0x6e51b90 {NSErrorFailingURLKey=http://example.com/api/ID/password/xml/,

Jede Hilfe ist willkommen !

  • Ich denke, Sie sind auf der Suche für die http-Authentifizierung: aktivieren Sie diesen link stackoverflow.com/questions/1973325/...
  • Ich bin auch vor dem gleichen Problem bei der Authentifizierung der Anmeldeinformationen. Aber, dies geschieht nur zum zweiten mal die Validierung, zum ersten mal die Anmeldung funktioniert und signout-und login schlägt fehl.
  • poste bitte die Lösung, wenn u aufgelöst
  • Überprüfen Sie, ob die NSURLProtectionSpace, die Sie von der server ist die gleiche, die Sie zur Verfügung stellen NSURLCredentialStorage. Der server hat wahrscheinlich etwas einstellen um das Reich.
  • Benutzt du einen proxy? Ich hatte das gleiche Problem mit einem proxy
InformationsquelleAutor Piyush | 2012-07-23
Schreibe einen Kommentar