title: iOS Download html file from url
body: <p>I need to download the html file from server url and replace to local html file. I'm using AFNetworking to download the file and store to Documents folder. It's downloading video &amp; audio files. But when i try to download the html files i'm getting below error <code>Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x83d0730 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}</code></p>
  
  <pre><code> NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
   NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"solarhtml"];
  
   if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath])
   [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&amp;error];
  
   AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
   [manager.requestSerializer setValue:@"application/x-www-form-urlencoded"
   forHTTPHeaderField:@"Content-Type"];
  
   [manager setResponseSerializer:[AFJSONResponseSerializer serializer]];
   manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
  
  
   [manager GET:@"http://server.net/projects/index.html"
   parameters:nil
   success:^(AFHTTPRequestOperation *operation, id responseObject) {
   [operation.responseData writeToFile:[dataPath stringByAppendingPathComponent:@"index.html"] atomically:YES];
  
  
   NSLog(@"Successfully downloaded file to %@", [NSURL fileURLWithPath:dataPath]);
   NSLog(@"THE RESPONSE: %@", responseObject);
  
  
   }
   failure:^(AFHTTPRequestOperation *operation, NSError *error1) {
   NSLog(@"%@", error1);
   }];
  </code></pre>
  
  <p>Access html file:</p>
  
  <pre><code>  -(void)estimatesavings:(id)sender{
  
  
        if(updateclick==YES){
  
          web_estimate=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
  
          NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
          NSString *documentsDirectory = [paths objectAtIndex:0];
          NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"index.html"];
  
          NSURL *targetURL = [NSURL fileURLWithPath:filePath];
          NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
          [web_estimate loadRequest:request];
  
          web_estimate.delegate=self;
  
          [self.view addSubview:web_estimate];
  
      }else{
  
  
      NSString *pathToBundle = [[NSBundle mainBundle] bundlePath];
      NSURL *baseURL = [NSURL fileURLWithPath:pathToBundle];
      NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
      NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
      //CGRect fullScreenRect=[[UIScreen mainScreen]applicationFrame];
      web_estimate=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
      [web_estimate loadHTMLString:htmlString baseURL:baseURL];
  
  
  
      web_estimate.delegate=self;
      [self.view addSubview:web_estimate];
  
      }
  
  
      }
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>copy failed: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x83c8b50 {NSSourceFilePathErrorKey=/Users/ranganathagv/Library/Application Support/iPhone Simulator/6.1/Applications/CEDFEBEB-2A5C-40A9-8965-761689FD83C2/ActewAGL.app/index.html, NSUserStringVariant=(
      Copy
  ), NSFilePath=/Users/ranganathagv/Library/Application Support/iPhone Simulator/6.1/Applications/CEDFEBEB-2A5C-40A9-8965-761689FD83C2/ActewAGL.app/index.html, NSDestinationFilePath=/Users/ranganathagv/Library/Application Support/iPhone Simulator/6.1/Applications/CEDFEBEB-2A5C-40A9-8965-761689FD83C2/Documents/solarhtml/index.html, NSUnderlyingError=0x83c89c0 "The operation couldn’t be completed. No such file or directory"}c
  </code></pre>