4

I have a console application that I wrote for .NET/Windows that I suddenly had the need for on my unix system. Mono has, for the most part, been hugely successful at providing this for me.

There is however a small issue: The application issues many HttpWebRequests as it runs, and for a small portion of these, Mono is returning an error:

Error getting response stream (Write: The authentication or decryption has failed.): SendFailure

This error message seems to indicate an SSL error. However, this application does not issue any request to SSL-secured URIs (i.e. all URIs are http://).

The main code in question is as follows:

HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.UserAgent = UserAgent; req.AuthenticationLevel = AuthenticationLevel.None; req.AllowAutoRedirect = true; req.KeepAlive = true; req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); req.Timeout = timeout; if (useCompression) { req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); } 

Edit: For the purposes of running this code, you can define dummy variables as follows:

string url = "http://example.com"; string UserAgent = "WhateverBot"; int timeout = 5000; bool useCompression = true; 

It should be noted that the code works without any problem on Windows/.NET.

9
  • can you provide compilable examplecode and one or two urls which fail? Commented Aug 3, 2010 at 7:11
  • 1
    Are you sure the requested URL does not redirect you to an SSL version? Does it work in Windows environment? Have you consulted with any http monitoring tool to see the requests/responses? Commented Aug 3, 2010 at 7:59
  • @santa - Done. @Jaroslav Jandek - There are no problems on Windows. I do not have any evidence, but I think it's highly improbable that I'm being redirected to a secure website: This is happening for a variety of different URLs (and a variety of different hosts), but only for a small portion of all requests. There are certain practicalities which make http monitoring difficult, but I'll consider it as an option if a solution is not found easily. Commented Aug 3, 2010 at 8:36
  • 1
    @Jaro: that's what i intended to do... reproduce the error and monitor with wireshark... maybe there's really a bug in the mono-decompression-code... Commented Aug 3, 2010 at 14:03
  • does it work with mono under windows? or have you only tried MS.Net w/ Windows? Commented Aug 3, 2010 at 14:04

1 Answer 1

1

I also had this problem when running Mono in Windows even when the URL is not HTTPS. Let me say this loudly: ITS NOT REDIRECTED.

The solution has been to use the hack:

System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate { return true; }; 

My guess is that Mono does not look in the Windows keystore for certificates so does not find any so HTTPWebXXXX is not initialized correctly and then fails incorrectly.

My guess is that anyone taking the trouble to reproduce your error will know what they are doing with Mono (unlike me for example) and so have their environment set up correctly and be unable reproduce this real world problem.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.