[Mono-list] HttpWebRequest HTTPS problem

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


Hi,

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
.Create("https://www.google.com/accounts/ClientLogin");
            authRequest.KeepAlive = false;
            authRequest.ContentType = "application/x-www-form-urlencoded";
            authRequest.Method = "POST";

            //Build the POST data
            StringBuilder postBuilder = new StringBuilder();
            postBuilder.AppendFormat("accountType={0}",
GOOGLE_ACCOUNT_TYPE);
            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);

            requestStream.Close();

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

            string response = responseReader.ReadToEnd();

            //Always clean up after yourself
            responseReader.Close();
            responseStream.Close();

            //All we care about is the Auth value
            if (response.Contains("Auth"))
            {
                int index = response.LastIndexOf("=") + 1;
                string auth = response.Substring(index, response.Length -
index);
                return auth;
            }
            else
            {
                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
/usr/src/mono-1.2.6/mcs/class/System/System.Net/WebConnectionStream.cs:613
at GoogleDocumentManager.Authenticate () [0x000d8] in
/tmp/www-data-temp-aspnet-0/b9f31472/693a96d7._4.cs:286*
This works fine on Windows/IIS/ASP.NET
Any ideas what might be causing it?

Thank you.

Timothy.
-------------- 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