title: Objective-C equivalent of curl request
body: <p>I'm trying to manipulate this curl request in Objective-C:</p>
  
  <pre><code>curl -u username:password "http://www.example.com/myapi/getdata"
  </code></pre>
  
  <p>I've implemented the following and I'm getting a data get error <code>Domain=kCFErrorDomainCFNetwork Code=303</code> with <code>NSErrorFailingURLKey=http://www.example.com/myapi/getdata</code>:</p>
  
  <pre><code>// Make a call to the API to pull out the categories
  NSURL *url = [NSURL URLWithString:@"http://www.example.com/myapi/getdata"];
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  
  // Create the username:password string for the request
  NSString *loginString = [NSString stringWithFormat:@"%@:%@", API_USERNAME, API_PASSWORD];
  
  // Create the authorisation string from the username password string
  NSData *postData = [loginString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
  NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
  
  [request setURL:url];
  [request setHTTPMethod:@"GET"];
  [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
  [request setHTTPBody:postData];
  
  NSError *error;
  NSURLResponse *response;
  NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error];
  </code></pre>
  
  <p>I was hoping that someone could spot where I am going wrong with my attempt to manipulate the curl request and point me in the correct direction. Is there something obvious I'm missing out? The data returned from the API is in a JSON format.</p>