Obiektywny odpowiednik C dla żądania zwijania

Próbuję manipulować tym żądaniem curl w Objective-C:

curl -u username:password "http://www.example.com/myapi/getdata"

Zaimplementowałem następujące i otrzymuję błąd pobierania danychDomain=kCFErrorDomainCFNetwork Code=303 zNSErrorFailingURLKey=http://www.example.com/myapi/getdata:

// 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:&response error:&error];

Miałem nadzieję, że ktoś może zauważyć, gdzie popełniam błąd, próbując manipulować prośbą o zwinięcie i skierować mnie we właściwym kierunku. Czy brakuje mi czegoś oczywistego? Dane zwrócone z interfejsu API są w formacie JSON.

questionAnswers(2)

yourAnswerToTheQuestion