ios - Using AFNetworking with authentication fails with correct credentials -


i'm trying download .sqlite file companies ftp site using afnetworking. each ftp user has own folder on server. found this question handle authentication, , this question handle download. believe have meshed 2 correctly i'm looking (or atleast i'm not getting far enough able test yet). i've attached code here anyway.

afhttpclient subclass.h

#import "afhttpclient.h"  @interface afnetworkinghelper : afhttpclient  - (void) setusername:(nsstring *)username andpassword:(nsstring *)password;  + (afnetworkinghelper *)sharedmanager;  @end 

afhttpclient subclass.m

#import "afnetworkinghelper.h" @implementation afnetworkinghelper  #pragma mark - methods - (void)setusername:(nsstring *)username andpassword:(nsstring *)password {     [self clearauthorizationheader];     [self setauthorizationheaderwithusername:username password:password]; }  #pragma mark - initialization - (id) initwithbaseurl:(nsurl *)url {     self = [super initwithbaseurl:url];     if (!self)     {         return nil;     }      return self; }  #pragma mark - singleton methods + (afnetworkinghelper *)sharedmanager {     static dispatch_once_t pred;     static afnetworkinghelper *_sharedmanager = nil;      dispatch_once(&pred, ^{ _sharedmanager = [[self alloc] initwithbaseurl:[nsurl urlwithstring:@"ftp://www.mysite.net"]]; });     return _sharedmanager; }  @end 

viewcontroller.m

// download data - afnetworking method [[afnetworkinghelper sharedmanager] setusername:@"myusername" andpassword:@"mypassword"]; [[afnetworkinghelper sharedmanager] getpath:@"/myfile.sqlite" parameters:nil success:^(afhttprequestoperation *operation, id responseobject) {      nsurl *path = [[[app applicationdocumentsdirectory] urlbyappendingpathcomponent:@"myfile"] urlbyappendingpathextension:@"sqlite"];      operation.outputstream = [nsoutputstream outputstreamwithurl:path append:no];      [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject)      {           nslog(@"successfully downloaded file path: %@",path);           // update dates table reflect info updated here      }                                      failure:^(afhttprequestoperation *operation, nserror *error)      {            nslog(@"error in afhttprequestoperation in clickedbuttonatindex on mycontroller.m");            nslog(@"%@",error.description);       }];        [operation start];   }                           failure:^(afhttprequestoperation *operation, nserror *error)   {         nslog(@"error in afhttprequestoperation in clickedbuttonatindex on mycontroller.m");         nslog(@"%@",error.description);    }]; 

the problem i'm having i'm getting nsurlerrordomain code=-1102 "you not have permission access requested resource" when try run it. have verified username , password i'm sending correct. if try pass path file doesn't exist, still -1102 error (instead of error saying file requested doesn't exist, error expected get). if type path first question linked browser, i'm getting different behavior based on browser use:

  • firefox: have enter path without username, file (so ftp://www.mysite.net/myfile.sqlite). when enter address bar, popup asking username , password. when enter correct credentials, file download begins , completes successfully.
  • ie: have enter path username , file, (so ftp://www.mysite.net/myuser/myfile.sqlite). when enter address bar, popup asking username , password. when enter correct credentials, file download begins , completes successfully.
  • safari: no matter how enter path, error screen saying you don't have permission open page. not credential prompt, nor download ever start. if try enter path file doesn't exist, still error saying you don't have permission open page (just when tried requesting non-existent file in app). update: using "username:password@www..." syntax per @rog's comment allows me download in safari.

i don't understand what's going on here. getting error message app because never getting credential challenge, when try open safari? if so, why don't challenge credentials app or safari when use other browsers? there way can check if app trying use credentials i've supplied when tries download file?

ftp , http 2 different protocols.

using afhttpclient ftp server not going work. afnetworking supports ftp afurlconnectionoperation; else http.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -