0

I am working on the background thread module of getting the current time being displayed on the webpage as 10-06-2014 16:19:11. When it comes to the execution, no data is get. Would you please tell me how to create the inputStream and read the web content ? Assume that https link is working Given the message is : The certificate for this server is invalid.Would you like to connect to the server anyway?,

The below is my message

2014-06-10 16:46:16.292 marker[2724:7707] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
2014-06-10 16:46:16.296 marker[2724:60b] Error = Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “dc02.cei-hk.net” which could put your confidential information at risk.

" UserInfo=0x146be370 {NSErrorFailingURLStringKey=https://dc02.cei-hk.net:8081/GetTime.aspx, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, 
NSErrorFailingURLKey=https://dc02.csd-hk.net:8081/GetTime.aspx, NSLocalizedDescript`

ion=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “dc02.cei-hk.net” which could put your confidential information at risk., NSUnderlyingError=0x14582870 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “dc02.csd-hk.net” which could put your confidential information at risk.", NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x14675820>}`

The below is my code

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    dispatch_async(dispatch_get_main_queue(), ^{
        NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://dc02.csd-hk.net:8081/GetTime.aspx",nil]];
        NSError *error = nil;
        NSURLRequest *request = [NSURLRequest  requestWithURL:jsonURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0 ];

        NSData *responsedata = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
        NSString* jsonData = [[NSString alloc] initWithData:responsedata encoding:NSUTF8StringEncoding];

   //     NSString *json = [NSString stringWithContentsOfURL:url   encoding:NSUTF8StringEncoding error:&error];
        if( jsonData.length > 0 )
        {
            NSLog(@"Text=%@", jsonData);
            [ToastView showToastInParentView:self.view withText:jsonData withDuaration:5.0];
        }
        else 
        {
            NSLog(@"Error = %@", error);
        }
    });

});

Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

1 Answers1

1

Your URL cannot be resolved, so you better check it twice.

Have a look at this for alternative services.

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • what happens now is that the server you are using does not have a recognised SSL certificate (CURL on OS X is also rejecting it for the same reason). Either you find a service which runs on http (so you do not need a certificate), if it is ok for you, or you set things up so to ignore the error like suggested here:http://stackoverflow.com/questions/6792213/ignoring-invalid-server-certificates-with-uiwebview – sergio Jun 10 '14 at 09:51