Project

General

Profile

Unable to use REST API over https

Added by Andreas Huber almost 12 years ago

Hi

Our internal Redmine server only allows me to connect via https. Here's how I tried to use the REST API via https from .NET:

  1. As suggested on Using the REST API with .NET, setting the host variable to "https://redmine.company.com/redmine/" and the apiKey to "ffffffffffffffffffffffffffffffffffffffff".
  2. From scratch with the following code:
    using System.IO;
    using System.Net;
    
    class Program
    {
        static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => true;
    
            var request = (HttpWebRequest)WebRequest.Create(
                "https://redmine.company.com/redmine/issues/149.xml?key=ffffffffffffffffffffffffffffffffffffffff");
            request.CookieContainer = new CookieContainer();
            request.Method = "GET";
    
            using (var response = request.GetResponse()) // Hangs here
            using (var responseStream = response.GetResponseStream())
            using (var memoryStream = new MemoryStream())
            {
                responseStream.CopyTo(memoryStream);
            }
        }
    }

Of course, company.com and ffffffffffffffffffffffffffffffffffffffff are just placeholders for my real company and my real API key on my account page. Both attempts hang for some time before timing out with a WebException (see Hangs here comment in attempt 2). I then tried to download other stuff from the Redmine server (like e.g. time_entries.csv, atom feeds, etc.), each time with exactly the same result.

So far so bad. However, if I copy-paste the URL https://redmine.company.com/redmine/issues/149.xml?key=ffffffffffffffffffffffffffffffffffffffff into my browser, I get exactly the response I would expect. So, it seems as though our Redmine server behaves as it should, but somehow I can't get it to work from .NET.

I realize this might have absolutely nothing to do with Redmine, but I have successfully downloaded stuff from other https sites and have managed to download issue data from http://demo.redmine.org with the code of attempt 2 (of course with adapted URLs, etc). So, it seems there might be something special about how Redmine communicates over https.

If anybody is successfully using the REST API over https from .NET, I'd be really grateful for some pointers on what I'm doing wrong.

Thanks,

Andreas


Replies (3)

RE: Unable to use REST API over https - Added by Matthias Lohr almost 12 years ago

Maybe there's a problem with your CA? Is your .NET able to verify valid SSL certificates?

RE: Unable to use REST API over https - Added by Andreas Huber almost 12 years ago

Matthias Lohr wrote:

Maybe there's a problem with your CA? Is your .NET able to verify valid SSL certificates?

Actually, it's a self-signed certificate, which is not verifyable against a CA. However, the line

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => true;

should take care of that fact by accepting all certificates. However, the program never seems to get that far, as a breakpoint set on that callback is never hit.

RE: Unable to use REST API over https - Added by m butch3r over 11 years ago

i've had good luck using jersey. Not sure what the .net counterpart would be...

    (1-3/3)