title: How can I make multiple authenticated Requests to web server with one NSURLConnection?
body: <p>I would like to to get fetch JSON from <a href="http://mycompany.com/jsonpage1..etc" rel="nofollow">http://mycompany.com/jsonpage1..etc</a>. The webserver requires initial login <a href="http://mycompany.com/login" rel="nofollow">http://mycompany.com/login</a>, and after that a cookie is maintained for the user. How do I get this behavior with NSURLCredentialStorage without asking to login every time? Here is the non-working code using NSURLCredential Storage</p>
  
  <pre><code>- (IBAction)getJSON:(id)sender
  {
  
  //  [self establishSession];
  
  NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user"
                                                           password:@"pass"
                                                            persistence:NSURLCredentialPersistenceForSession];
  
  NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                           initWithHost:@"myCompany.com"
                                           port:0
                                           protocol:@"http"
                                           realm:nil
                                           authenticationMethod:nil];
  
  [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential
                                                      forProtectionSpace:protectionSpace];
  
  
  //////////GET JSON//////////////
  
  NSError *error;
  NSURL *url = [NSURL URLWithString:@"http://mycompany.com.jsonpage1"];
   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  [[NSURLConnection alloc] initWithRequest:request delegate:self];
  }
  
   //I am NOT getting JSON in this delegate
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  
  NSString *responseString = [[NSString alloc] initWithData:responseData    encoding:NSUTF8StringEncoding];
  
  NSLog(@"%@",responseString);
  
  }
  </code></pre>