Just wanted to follow up and share that we've resolved this issue.  It
was a classic case of a problem between the keyboard and the chair.  The
ASP.Net code we ported to MT was not URL encoding the POST data, despite
the fact that the POST data had a number of characters that should have
been escaped.  Once I changed the MT code to URL encode the POST data
before writing it to the request stream, everything started working as
expected.  It seems as though the native .Net HttpWebRequest
automatically URL encodes any POST data but the Mono implementation of
HttpWebRequest does not.

Chris

-----Original Message-----
From: Chris House 
Sent: Friday, February 17, 2012 1:00 PM
To: [email protected]
Subject: Re: Timeout when doing POST via HttpWebRequest

Yes, I am absolutely sure the URL I'm trying to post to does accept POST
requests.  The code I'm working with is a direct port from an ASP.Net
project.  I can execute this code in the ASP.Net project and it works
without any timeouts.

I ran the curl command you suggested.  It returned without error.  I'm
not terribly familiar with curl so I don't know if that is expected or
not.

Regarding closing the request stream, that causes the following
exception:

"System.Net.WebException: Error getting response stream (ReadDone2):
ReceiveFailure ---> System.Exception:    at
System.Net.WebConnection.HandleError(WebExceptionStatus st,
System.Exception e, System.String where)\n   at
System.Net.WebConnection.ReadDone(IAsyncResult result)\n  at
System.Net.WebConnection.HandleError (WebExceptionStatus st,
System.Exception e, System.String where) [0x0003a] in
/Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnecti
on.cs:399 \n  --- End of inner exception stack trace ---\n  at
System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
[0x0005e] in
/Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequ
est.cs:828 \n  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in
/Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequ
est.cs:836 \n  at SsoSpike.CookieController2.Initialize () [0x00097] in
/Users/christopher/Documents/Development/ProAg/SsoSpike/SsoSpike/CookieC
ontroller2.cs:281 "


Date: Fri, 17 Feb 2012 10:41:05 -0500
From: Jackson Harper <[email protected]>
To: [email protected]
Subject: Re: [MonoTouch] Timeout when doing POST via HttpWebRequest
        with content written to request stream
Message-ID:
        
<capgstfhb+zleu+5fpsphhqwqhwu+gjvsxx4zdvqw009u4uu...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"

Are you absolutely sure the supplied URL accepts POST requests?  Does
the following command work?

curl -d 'foo=bar&baz=boo' <your url>

Also, I think you might need to close the request stream before you get
the response.

Jackson



On Fri, Feb 17, 2012 at 10:23 AM, Chris House <[email protected]>
wrote:

> Greetings ? I?m working on my first MonoTouch app (other than Hello 
> World of course).  I?m trying to do a POST to a web address so  I can 
> get an authentication cookie that will be used in subsequent RESTful 
> calls.  What I?m seeing is that when I do the post and include the 
> post data in  the request stream, it times out when I call 
> HttpWebRequest.GetResponse().  If I remove the line of code that 
> writes to the request stream then I don?t get a timeout.  ****
>
> ** **
>
> Here?s what the code looks like:****
>
> ** **
>
> HttpWebRequest authRequest =
> (HttpWebRequest)WebRequest.Create(this.AuthActionUrl);****
>
> authRequest.AllowAutoRedirect = false;****
>
> authRequest.Method = ?POST?;****
>
> byte[] postData = this.GetPostData();****
>
> authRequest.ContentType = ?application/x-www-form-urlencoded?;****
>
> authRequest.GetRequestStream.Write(postData, 0, postData.Length);  // 
> Commenting this line out eliminates the timeout****
>
> authRequest.Headers.Add(Constants.SingleSignOn.COOKIE, string.Joing(? 
> ?,
> cookieJar.ToArray()));****
>
> ** **
>
> using (HttpWebResponse authResponse =
> (HttpWebResponse)authRequest.GetResponse())  // This is where the 
> timeout
> occurs****
>
> {****
>
>   cookieJar.Clear();****
>
>   ProcessCookies(authResponse);****
>
> }****
>
> ** **
>
> Any suggestions would be appreciated.****
>
> ** **
>
> Thanks,****
>
> ** **
>
> Chris****
>
> ** **
>
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to