Reputation: 1035
I'm trying to connect to a web service that if I hit it through Safari I get back some json, but when I hit it through code I get a NSURLErrorDomain error with the following description.
"The certificate for this server is invalid. You might be connecting to a server that is pretending to be "url" which could..."
Here is the code:
NSURL *url = [NSURL URLWithString:@"webservice_url"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
NSError *error = nil;
NSHTTPURLResponse *responseCode = nil;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
Can anyone explain how to get around this? Also, it is a https web service.
Upvotes: 0
Views: 2882
Reputation: 722
You can use like this -
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL];
// http://example.com/v1/foo
Upvotes: 0
Reputation: 655
The website doesn't have a HTTPS certificate. Try looking into this: https://stackoverflow.com/a/15011030/4716039
Upvotes: 1
Reputation: 3628
In your code, the URLWithString value needs to be an actual URL. It is the same thing as going to Safari and typing in "webservice_url" as the entire URL instead of giving it the entire address. Instead you'll want to do something like the following:
NSURL *url = [NSURL URLWithString:@"https://www.urlgoeshere.com/getJSON"];
Upvotes: 0