Hi,
I want to access a web login page from C#, in other words I want to login to a remote web site using C# rather than a browser.
So, how do you POST from C#? (hopefully, using WebRequest and WebResponse)
Please give an example or point me to one.
Thanks,
T
How Post from C#?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


AnttiRank #9,295 · 208 reputationPosted Dec 15, 2005, 7:15 PM EST
I don't remember the exact code right now, but first you create HttpWebRequest object like this (this is the synchronous way, asyncronous is much more difficult):
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.yousite.abc");Then you set AllowWriteStreamBuffering to true for request object, and you can set suitable Timeout. You also must set Method property to "POST". Then you create a System.IO.Stream, request has method called GetRequestStream, and Write your data there (variable1=value1?variable2=value2 etc...). If you are connecting using a proxy server, you must add a Proxy to response object too. request.GetResponse() executes the webcall. That gives you a HttpWebResponse object, which has also a Stream, you get it with GetResponseStream. You can read it with ReadToEnd method.
Hope this helps
Will Wagers104 reputationPosted Jun 5, 2006, 1:38 PM EDT
http://www.csharp-online.net/csow/index.php?title=HTTP_Post