0

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.

Oscar
  • 1,025
  • 2
  • 15
  • 25

3 Answers3

1

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

Community
  • 1
  • 1
Peter Lendvay
  • 565
  • 4
  • 22
0

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"];
c_rath
  • 3,618
  • 2
  • 22
  • 14
0

You can use like this -

NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];

[NSURL URLWithString:@"foo" relativeToURL:baseURL];
// http://example.com/v1/foo
Uttam Sinha
  • 722
  • 6
  • 9