Using Visual Studio for Mac, I've created a RESFUL API (developed from API project template), which out of the box outputs a very simple JSON file (i.e. ["value1","value2"]) at the following url: https://localhost:5001/api/values.
So, while running the API on Visual Studio in the background, I'm also running XCode on the same computer; in that I'm developing an app which needs to connect to the API url and output the expected JSON response.
The problem is it continually fails due to a trust error: "TIC SSL Trust Error...NSURLSession/NSURLConnection HTTP Load failed".
From what I've researched, I believe I need to install the self-signed certificate of localhost onto my XCode emulator in order for it to permit the app to trust the url. How do I get access to this localhost certificate?
Or is this even the right way to go?
Code that generates the trust error:
// Specify the base url...
static NSString *const API_URL = @"https://localhost:5001";
// Specify completed url ...
NSString *urlAppend = [NSString stringWithFormat:@"/api/values"];
NSString *urlStr = [[[NSString alloc] initWithString:API_URL]
stringByAppendingString:urlAppend];
// Specify the URL object that can return JSON, XML, etc....
NSURL *url = [[NSURL alloc] initWithString:urlStr];
// Create an NSURLSessionDataTask that does the GET request at the specified URL (using NSURLSession shared session)...
NSURLSessionDataTask *task = [[NSURLSession sharedSession]
dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
// Handle response (output respnose to log window))...
NSLog(@"%@", [output initWithData:data encoding:(NSASCIIStringEncoding)] ? : @"no data");
}];
// Start task ....
[task resume];