[Mono-list] HttpWebRequest HTTPS problem

Timothy Parez timothyparez at gmail.com
Tue Jan 29 06:34:55 EST 2008


I have the following code as part of an ASP.NET <http://asp.net/>application.
Hosted on Ubuntu with Mono 1.2.6 Apache2/mod_mono:

    private string Authenticate(string Username, string Password)
            //Create a web request for the Google ClientLogin service
            HttpWebRequest authRequest = (HttpWebRequest)HttpWebRequest
            authRequest.KeepAlive = false;
            authRequest.ContentType = "application/x-www-form-urlencoded";
            authRequest.Method = "POST";

            //Build the POST data
            StringBuilder postBuilder = new StringBuilder();
            postBuilder.AppendFormat("&Email={0}", Username);
            postBuilder.AppendFormat("&Passwd={0}", Password);
            postBuilder.AppendFormat("&service={0}", GOOGLE_SERVICE);
            postBuilder.AppendFormat("&source={0}", GOOGLE_SOURCE);

            //Convert the POST data to a byte[]
            byte[] data = ASCIIEncoding.ASCII.GetBytes(postBuilder.ToString
            authRequest.ContentLength = data.Length;

            //Get the request stream and POST the data
            Stream requestStream = authRequest.GetRequestStream();
            requestStream.Write(data, 0, data.Length);


            //Get the response
            HttpWebResponse authResponse =
            Stream responseStream = authResponse.GetResponseStream();
            StreamReader responseReader = new StreamReader(responseStream);

            string response = responseReader.ReadToEnd();

            //Always clean up after yourself

            //All we care about is the Auth value
            if (response.Contains("Auth"))
                int index = response.LastIndexOf("=") + 1;
                string auth = response.Substring(index, response.Length -
                return auth;
                throw new Exception(response);
                //return "";

When this code is executed I get the following exception:

*System.Net.WebException: Error writing request. at
System.Net.WebConnectionStream.WriteRequest () [0x00169] in /usr/src/mono-
1.2.6/mcs/class/System/System.Net/WebConnectionStream.cs:563 at
System.Net.WebConnectionStream.Close () [0x000e0] in
at GoogleDocumentManager.Authenticate () [0x000d8] in
This works fine on Windows/IIS/ASP.NET
Any ideas what might be causing it?

Thank you.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20080129/a0944433/attachment-0001.html 

More information about the Mono-list mailing list