Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8353615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:18:59+00:00 2026-06-09T09:18:59+00:00

There’s a load of questions which ask this: Can I get UIWebView to view

  • 0

There’s a load of questions which ask this: Can I get UIWebView to view a self signed HTTPS website?

And the answers always involve either:

  1. Use the private api call for NSURLRequest: allowsAnyHTTPSCertificateForHost
  2. Use NSURLConnection instead and the delegate canAuthenticateAgainstProtectionSpace etc

For me, these won’t do.
(1) – means I can’t submit to the app store successfully.
(2) – using NSURLConnection means the CSS, images and other things that have to be fetched from the server after receiving the initial HTML page do not load.

Does anyone know how to use UIWebView to view a self-signed https webpage please, which does not involve the two methods above?

Or – If using NSURLConnection can in fact be used to render a webpage complete with CSS, images and everything else – that would be great!

Cheers,
Stretch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:19:00+00:00Added an answer on June 9, 2026 at 9:19 am

    Finally I got it!

    What you can do is this:

    Initiate your request using UIWebView as normal. Then – in webView:shouldStartLoadWithRequest – we reply NO, and instead start an NSURLConnection with the same request.

    Using NSURLConnection, you can communicate with a self-signed server, as we have the ability to control the authentication through the extra delegate methods which are not available to a UIWebView. So using connection:didReceiveAuthenticationChallenge we can authenticate against the self signed server.

    Then, in connection:didReceiveData, we cancel the NSURLConnection request, and start the same request again using UIWebView – which will work now, because we’ve already got through the server authentication 🙂

    Here are the relevant code snippets below.

    Note: Instance variables you will see are of the following type:
    UIWebView *_web
    NSURLConnection *_urlConnection
    NSURLRequest *_request

    (I use an instance var for _request as in my case it’s a POST with lots of login details, but you could change to use the request passed in as arguments to the methods if you needed.)

    #pragma mark - Webview delegate
    
    // Note: This method is particularly important. As the server is using a self signed certificate,
    // we cannot use just UIWebView - as it doesn't allow for using self-certs. Instead, we stop the
    // request in this method below, create an NSURLConnection (which can allow self-certs via the delegate methods
    // which UIWebView does not have), authenticate using NSURLConnection, then use another UIWebView to complete
    // the loading and viewing of the page. See connection:didReceiveAuthenticationChallenge to see how this works.
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    {
        NSLog(@"Did start loading: %@ auth:%d", [[request URL] absoluteString], _authenticated);
    
        if (!_authenticated) {
            _authenticated = NO;
    
            _urlConnection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
    
            [_urlConnection start];
    
            return NO;
        }
    
        return YES;
    }
    
    
    #pragma mark - NURLConnection delegate
    
    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
    {
        NSLog(@"WebController Got auth challange via NSURLConnection");
    
        if ([challenge previousFailureCount] == 0)
        {
            _authenticated = YES;
    
            NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
    
            [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
    
        } else
        {
            [[challenge sender] cancelAuthenticationChallenge:challenge];
        }
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
    {
        NSLog(@"WebController received response via NSURLConnection");
    
        // remake a webview call now that authentication has passed ok.
        _authenticated = YES;
        [_web loadRequest:_request];
    
        // Cancel the URL connection otherwise we double up (webview + url connection, same url = no good!)
        [_urlConnection cancel];
    }
    
    // We use this method is to accept an untrusted site which unfortunately we need to do, as our PVM servers are self signed.
    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
    {
        return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
    }
    

    I hope this helps others with the same issue I was having!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many similar questions to this one, but they all ask about setting
There's no Sort() function for IList . Can someoene help me with this? I
there can be two productions from which we can do the reduction. After giving
I know there's a lot of other questions out there that deal with this
There are plenty of questions and answers to this like this question but I
There's a lot of reading on self referencing problems, but I can't seem to
There is a column that exists in 2 tables. In table 1, this column
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There is a directed graph having a single designated node called root from which
There are two intents on the receiver side which are called from the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.