Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can check this <a href="https://stackoverflow.com/questions/12828060/authentication-with-nsurlconnection-sendasynchronousrequest-with-completion-hand">answer</a>. I would suggest using <a href="https://github.com/gowalla/AFNetworking" rel="nofollow noreferrer">AFNetworking</a> too.</p> <p>If you are using basic HTTP authentication I don't see a need to specifically request an authentication URL, you should simply request the JSON API in the first place. If you have the username and password beforehand you should set them in the header before making the request:</p> <pre><code>#import "NSData+Base64.h" ... NSString *authStr = [NSString stringWithFormat:@"%@:%@", @"username", @"pass"]; NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding]; NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedString]]; [request setValue:authValue forHTTPHeaderField:@"Authorization"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setHTTPMethod:@"POST"]; </code></pre> <p>The code above has the NSData+Base64.h dependency, you will have to add it to your project, you can download it in: <a href="http://projectswithlove.com/projects/NSData_Base64.zip" rel="nofollow noreferrer">NSData+Base64 class and header</a></p> <p>In the case you are prompting the user for credentials (which is not shown in your code) and you do need to set the credentials in the connection:didReceiveAuthenticationChallenge the same still applies you can just use the URL you are trying to create inside the authentication challenge method:</p> <pre><code>// Second JSON Request API here </code></pre>
 

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