Equivalente a Objective-C do pedido de curvatura
Estou tentando manipular este pedido de curl em Objective-C:
curl -u username:password "http://www.example.com/myapi/getdata"
Eu implementei o seguinte e estou recebendo um erro de recebimento de dadosDomain=kCFErrorDomainCFNetwork Code=303
comNSErrorFailingURLKey=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];
Eu estava esperando que alguém pudesse identificar onde estou errado com a minha tentativa de manipular o pedido de onda e me apontar na direção correta. Existe algo óbvio que estou perdendo? Os dados retornados da API estão em um formato JSON.