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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Nick
  • 1,799
  • 13
  • 13
  • can you provide compilable examplecode and one or two urls which fail? – santa Aug 03 '10 at 07: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? – Jaroslav Jandek Aug 03 '10 at 07: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. – Nick Aug 03 '10 at 08: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... – santa Aug 03 '10 at 14:03
  • does it work with mono under windows? or have you only tried MS.Net w/ Windows? – santa Aug 03 '10 at 14:04
  • @santa: I've only tested it with MS.NET on Windows. – Nick Aug 04 '10 at 09:22
  • @nick: try it w/ mono under windows if possible, I'll have no possibility to try to reproduce your error this week I guess... on the other hand - if time is no problem, just wait for it - I'll give it a shot as soon as I can :-) – santa Aug 04 '10 at 16:18
  • I can confirm this code works fine under Mono on Windows (using MonoDevelop on Windows 7, 32-bit). – karlgrz Feb 10 '11 at 00:41
  • What version of mono were you using? I just tested this on MonoDevelop 2.4 on Ubuntu 10.04 and successfully ran through a test of 10,000 requests without any being refused. – karlgrz Feb 10 '11 at 00:54

1 Answers1

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Bill
  • 11
  • 1