receive Directory from NAS with NSURLSession

51 views Asked by At

i´m new to NSURLSession and i want connect to my local NAS Server with this code:

NSURL *url = [NSURL URLWithString:@"http://192.168.1.2/"];
    NSString * user = [NSString stringWithUTF8String:"admin"];
    NSString * password = [NSString stringWithUTF8String:"xxx"];
    NSURLProtectionSpace * protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:url.host port:[url.port integerValue] protocol:url.scheme realm:nil authenticationMethod:NSURLAuthenticationMethodHTTPBasic];

    NSURLCredential *cred = [NSURLCredential
                             credentialWithUser:user
                             password:password
                             persistence:NSURLCredentialPersistenceForSession];


    NSURLCredentialStorage * cred_storage ;
    [cred_storage setCredential:cred forProtectionSpace:protectionSpace];

    NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    sessionConfiguration.URLCredentialStorage = cred_storage;
    sessionConfiguration.allowsCellularAccess = YES;

    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];
    NSLog(@"viewdidload");

    NSURLSessionDataTask *task = [session dataTaskWithURL:url];
    [task resume];

my request returns a status code 200 and in my delegate method:

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
    didReceiveData:(NSData *)data{

    NSString *dataString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

    NSLog(@"didReceiveData:%@", dataString);

}

i get this log:

didReceiveData:

Index_Page

var queryArg = location.search; if (queryArg.substring(1,5) == "url=") {
  var hiddenURL = queryArg.substring(5,queryArg.length);
} else if (queryArg.substring(1,7) == "mount=" ) {
  var hiddenURL = queryArg.substring(7,queryArg.length);
} else {
  var hiddenURL = "";
} if (hiddenURL == "") {
  var seperateHref = window.location.href.split("/");

  if (seperateHref[0] == "https:")

      window.location =
"https://"+seperateHref[2]+"/"+seperateHref[3]+"/desktop,/login.html";
  else

      window.location =
"http://"+seperateHref[2]+"/"+seperateHref[3]+"/desktop,/login.html"; } else {
  location.replace("/desktop,/login.html"+queryArg);
}

why won´t my code authenticate with the NAS even when i passed user and pw? after i tried a bit, with no credential in my code, the didReceiveChallenge - delegateMethod never gets called too. i just want to receive the directories to fill up my tableview to create a simple file browser..

0

There are 0 answers