Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic HTTP Authentication on iPhone
    text
    copied!<p>I'm trying to get a small twitter client running and I ran into a problem when testing API calls that require authentication.</p> <p>My password has special characters in it, so when I try to use the following code it doesn't work.</p> <pre><code>NSString *post = [NSString stringWithFormat:@"status=%@", [status stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@@%@/statuses/update.json", username, password, TwitterHostname]]; [request setURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLResponse *response; NSError *error; [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; </code></pre> <p>I started looking into base64 and putting the authentication into the headers. I found <a href="http://www.dribin.org/dave/blog/archives/2006/03/12/base64_cocoa/" rel="noreferrer">Dave Dribin's</a> post on his base64 implementation, and it seemed to make sense. However when I tried to use it the compiler started complaining about how it couldn't find the openssl libraries. So I read that I needed to link in the libcrypto library, but it doesn't seem to exist for iphone.</p> <p>I've also read people saying that apple won't allow apps that use crypto libraries, which doesn't make sense to me.</p> <p>So now I'm kinda stuck and confused. What's the easiest way to get basic authentication into my app?</p> <p>Cheers</p>
 

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