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
Loading

Will WagersPosted Jun 5, 2006, 5:38 PM
http://www.csharp-online.net/csow/index.php?title=HTTP_Post
AnttiPosted Dec 16, 2005, 12:15 AM
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