Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the completionHandler method is for basic requests. Maybe you could consider using <a href="https://github.com/gowalla/AFNetworking" rel="nofollow noreferrer">AFNetworking</a> as I use this with block methods and authentication.</p> <p>EDIT.... Have you tried adding the authentication header to the NSURLRequest? Create an NSMutableURLRequest:</p> <pre><code>NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.example.com/"]]; </code></pre> <p>And add the authentication header like this:</p> <pre><code>NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", userName, password]; NSString *authValue = [NSString stringWithFormat:@"Basic %@", AFBase64EncodedStringFromString(basicAuthCredentials)]; [urlRequest setValue:authValue forHTTPHeaderField:@"Authorization"]; </code></pre> <p>The AFBase64EncodedStringFromString function is this:</p> <pre><code>static NSString * AFBase64EncodedStringFromString(NSString *string) { NSData *data = [NSData dataWithBytes:[string UTF8String] length:[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; NSUInteger length = [data length]; NSMutableData *mutableData = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; uint8_t *input = (uint8_t *)[data bytes]; uint8_t *output = (uint8_t *)[mutableData mutableBytes]; for (NSUInteger i = 0; i &lt; length; i += 3) { NSUInteger value = 0; for (NSUInteger j = i; j &lt; (i + 3); j++) { value &lt;&lt;= 8; if (j &lt; length) { value |= (0xFF &amp; input[j]); } } static uint8_t const kAFBase64EncodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; NSUInteger idx = (i / 3) * 4; output[idx + 0] = kAFBase64EncodingTable[(value &gt;&gt; 18) &amp; 0x3F]; output[idx + 1] = kAFBase64EncodingTable[(value &gt;&gt; 12) &amp; 0x3F]; output[idx + 2] = (i + 1) &lt; length ? kAFBase64EncodingTable[(value &gt;&gt; 6) &amp; 0x3F] : '='; output[idx + 3] = (i + 2) &lt; length ? kAFBase64EncodingTable[(value &gt;&gt; 0) &amp; 0x3F] : '='; } return [[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding]; } </code></pre> <p>Then call the function you called before, but using your new NSURLRequest:</p> <pre><code>[NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload