[Mono-list] HttpWebRequest HTTPS problem - WebExceptionStatus.SendFailure
Timothy Parez
timothyparez at gmail.com
Tue Jan 29 17:39:11 EST 2008
This is the exact location where the exception is thrown:
//Get the request stream and POST the data
Stream requestStream = authRequest.GetRequestStream();
requestStream.Write(data, 0, data.Length);
requestStream.Close();
Timothy.
On 29 Jan 2008, at 23:31, Timothy Parez wrote:
>
> --Apple-Mail-1-369380
> Content-Type: text/plain;
> charset=US-ASCII;
> format=flowed;
> delsp=yes
> Content-Transfer-Encoding: 7bit
>
> Hi,
>
> Someone pointed me to this document:
> http://www.mono-project.com/UsingTrustedRootsRespectfully
>
>
> But when I use something similar to the code on that page just to
> test:
> catch (WebException we) {
> if (we.Status != WebExceptionStatus.TrustFailure)
> throw;
> Console.WriteLine ("You do not trust the people who " +
> "issued the certificate being used by '{0}'." +
> " Please see the application help file on " +
> "the 'trust certificate' subject to learn " +
> "about how this can be fixed.", args [0]);
>
> It simply throws this again:
>
> error writing request.
>
> Description: Error processing request.
>
> Error Message: HTTP 500. System.Net.WebException: Error writing
> request.
>
> Stack Trace:
>
> 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 () [0x000b5] in /tmp/www-data-
> temp-aspnet-0/b9f31472/70040e1b._4.cs:279
>
> The actual status is WebExceptionStatus.SendFailure.
>
> Any ideas?
>
>
>
> On 29 Jan 2008, at 12:34, Timothy Parez wrote:
>
>> Hi,
>>
>> I have the following code as part of an 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.
>
>
> --Apple-Mail-1-369380
> Content-Type: text/html;
> charset=US-ASCII
> Content-Transfer-Encoding: quoted-printable
>
> <html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode:
> space; =
> -webkit-line-break: after-white-space; "><div>Hi,</div><div><br =
> class=3D"webkit-block-placeholder"></div><div>Someone pointed me to
> this =
> document:</div><div><div style=3D"margin-top: 0px; margin-right:
> 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "><a =
> href=3D"http://www.mono-project.com/
> UsingTrustedRootsRespectfully">http://=
> www.mono-project.com/UsingTrustedRootsRespectfully</a></div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><br class=3D"webkit-block-placeholder"></div></div><div><br =
> class=3D"webkit-block-placeholder"></div><div>But when I use
> something =
> similar to the code on that page just to test:</div><div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> ">catch (WebException we) {</div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; "><span class=3D"Apple-tab-
> span" =
> style=3D"white-space:pre"> </span>if (we.Status !=3D =
> WebExceptionStatus.TrustFailure)</div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; "><span class=3D"Apple-tab-
> span" =
> style=3D"white-space:pre"> =
> </span>throw;</div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "><span class=3D"Apple-tab-span" =
> style=3D"white-space:pre"> </span>Console.WriteLine =
> ("You do not trust the people who " + </div><div
> style=3D"margin-top:=
> 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
> normal normal normal 12px/normal Helvetica; "><span =
> class=3D"Apple-tab-span" style=3D"white-space:pre"> =
> </span>"issued the certificate being used by '{0}'." + </
> div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
> </span>" Please see the application help file on " =
> + </div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "><span class=3D"Apple-tab-span" =
> style=3D"white-space:pre"> </span>"the =
> 'trust certificate' subject to learn " + </div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
> </span>"about how this can be fixed.", args [0]);</div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><br class=3D"webkit-block-placeholder"></div><div style=3D"margin-
> top: =
> 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
> normal normal normal 12px/normal Helvetica; ">It simply throws this =
> again:</div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "><br class=3D"webkit-block-placeholder"></
> div><div=
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><div style=3D"margin-top: 0px; margin-right: 0px; margin-bottom:
> 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> ">error writing request.</div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; min-height: 14px; "><br></
> div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> ">Description: Error processing request.</div><div style=3D"margin-
> top: =
> 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
> normal normal normal 12px/normal Helvetica; min-height: 14px; =
> "><br></div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; ">Error Message: HTTP 500. =
> System.Net.WebException: Error writing request.</div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> min-height: 14px; "><br></div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; ">Stack Trace:</div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> min-height: 14px; "><br></div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; ">System.Net.WebException:
> Error =
> writing request.</div><div style=3D"margin-top: 0px; margin-right:
> 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "> at =
> System.Net.WebConnectionStream.WriteRequest () [0x00169] in =
> /usr/src/mono-1.2.6/mcs/class/System/System.Net/
> WebConnectionStream.cs:563=
> </div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "> at
> System.Net.WebConnectionStream.Close =
> () [0x000e0] in =
> /usr/src/mono-1.2.6/mcs/class/System/System.Net/
> WebConnectionStream.cs:613=
> </div><div style=3D"margin-top: 0px; margin-right: 0px; =
> margin-bottom: 0px; margin-left: 0px; font: normal normal normal =
> 12px/normal Helvetica; "> at
> GoogleDocumentManager.Authenticate () =
> [0x000b5] in =
> /tmp/www-data-temp-aspnet-0/b9f31472/70040e1b._4.cs:279 </
> div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><br class=3D"webkit-block-placeholder"></div><div style=3D"margin-
> top: =
> 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: =
> normal normal normal 12px/normal Helvetica; ">The actual status is =
> WebExceptionStatus.SendFailure.</div><div style=3D"margin-top: 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; "><br =
> class=3D"webkit-block-placeholder"></div><div style=3D"margin-top:
> 0px; =
> margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font:
> normal =
> normal normal 12px/normal Helvetica; ">Any ideas?</div><div =
> style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
> margin-left: 0px; font: normal normal normal 12px/normal Helvetica; =
> "><br class=3D"webkit-block-placeholder"></div></div></div><div><br =
> class=3D"webkit-block-placeholder"></div><br><div><div>On 29 Jan
> 2008, =
> at 12:34, Timothy Parez wrote:</div><br =
> class=3D"Apple-interchange-newline"><blockquote
> type=3D"cite">Hi,<br><br>I=
> have the following code as part of an <a href=3D"http://asp.net/" =
> target=3D"_blank">ASP.NET</a> application.<br>Hosted on Ubuntu with
> Mono =
> 1.2.6 Apache2/mod_mono:<br><br> private string =
> Authenticate(string Username, string Password)<br>
> =
> {<
> br
> > =
> //Create a web request for the Google ClientLogin =
> service
> <br> &nb=
> sp; HttpWebRequest authRequest =3D
> (HttpWebRequest)HttpWebRequest<div =
> id=3D"1fti" class=3D"ArwC7c ckChnd">.Create("<a =
> href=3D"https://www.google.com/accounts/ClientLogin" =
> target=3D"_blank">https://www.google.com/accounts/ClientLogin</
> a>");<br> =
> =
> authRequest.KeepAlive =3D =
> false
> ;<br> &nbs=
> p; authRequest.ContentType =3D =
> "application/x-www-form-
> urlencoded";<br> &nbs=
> p; authRequest.Method =3D =
> "POST
> ";<br><br>  =
> ; //Build the POST data<br> =
> =
> StringBuilder postBuilder =3D new =
> StringBuilder
> ();<br> =
> postBuilder.AppendFormat("accountType=3D{0}", =
> GOOGLE_ACCOUNT_TYPE
> );<br> &=
> nbsp; postBuilder.AppendFormat("&Email=3D{0}", =
> Username);<br> =
> =
> postBuilder.AppendFormat("&Passwd=3D{0}", =
> Password
> );<br> =
> postBuilder.AppendFormat("&service=3D{0}", =
> GOOGLE_SERVICE
> );<br> =
> postBuilder.AppendFormat("&source=3D{0}", =
> GOOGLE_SOURCE);<br> =
> <
> br
> > =
> //Convert the POST data to a =
> byte
> []<
> br> &nbs=
> p; byte[] data =3D =
> ASCIIEncoding
> .ASCII.GetBytes(postBuilder.ToString());<br>  =
> ; =
> authRequest.ContentLength =3D =
> data
> .Length
> ;<br><br> =
> //Get the request stream and POST the data<br> =
> =
> Stream requestStream =3D =
> authRequest
> .GetRequestStream();<br> &nb=
> sp; requestStream.Write(data, 0, =
> data
> .Length
> );<br><br>  =
> ; =
> requestStream
> .Close();<br><br> &n=
> bsp; //Get the =
> response
> <br> &n=
> bsp; HttpWebResponse authResponse =3D =
> (HttpWebResponse)authRequest.GetResponse();<br> =
> =
> Stream responseStream =3D =
> authResponse
> .GetResponseStream();<br> &=
> nbsp; StreamReader responseReader =3D new =
> StreamReader
> (responseStream);<br><br> &=
> nbsp; string response =3D =
> responseReader.ReadToEnd();<br><br> =
> =
> //Always clean up after =
> yourself
> <br> &n=
> bsp; =
> responseReader
> .Close();<br>  =
> ; =
> responseStream
> .Close();<br><br> &=
> nbsp; //All we care about is the Auth =
> value
> <br>  =
> ; if (response.Contains("Auth"))<br> =
> =
> {<
> br
> >
> &nb=
> sp; int index =3D response.LastIndexOf("=3D") + =
> 1
> ;<
> br
> > &n=
> bsp; string auth =3D response.Substring(index, =
> response.Length - =
> index
> );<br> &nb=
> sp; return =
> auth
> ;<
> br>  =
> ; }<br> =
> =
> else
> <
> br> =
> =
> {<
> br
> >
> &nb=
> sp; throw new =
> Exception
> (response);<br> &n=
> bsp; //return =
> "";<
> br
> > =
> }<br> }<br><br>When this code is executed I get
> the =
> following exception:<br> <br> <h2 style=3D"font-weight:
> normal;"><font =
> size=3D"2"><em><em>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/693
> --Apple-Mail-1-369380--
More information about the Mono-list
mailing list