Oscar
Oscar

Reputation: 1035

iOS Trying to call web service and I'm getting a NSURLErrorDomain error

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

Answers (3)

Uttam Sinha
Uttam Sinha

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

Peter Lendvay
Peter Lendvay

Reputation: 655

The website doesn't have a HTTPS certificate. Try looking into this: https://stackoverflow.com/a/15011030/4716039

Upvotes: 1

c_rath
c_rath

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

Related Questions