0

I want to get json data from web service witch requires a permission to access, when I type the url of the web service it asks me to enter a username and a password, I didn't know how to pass these two parameters in my code in xcode, I tried doing it like this but it didn't work, any ideas please

NSURL *aUrl = [NSURL URLWithString: @"http://firstluxe.com/api/search/search?query=vogue&language=1&output_format=JSON"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:60.0];

[request addValue:[NSString stringWithFormat:@"OAuth %@", password] forHTTPHeaderField:@"Authorization"];

[request setHTTPMethod:@"GET"];

NSError *error = nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error: &error];

NSDictionary *JSONDictionary = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error];
NSLog(@"Response : %@", JSONDictionary);

0 Answers0