I need to post data to a URL (https://somesite.com) to download file in responseStrem based on the parameters I posted. How can I do that using a C# console application?
Parameters: filename, userid, password, type
I need to post data to a URL (https://somesite.com) to download file in responseStrem based on the parameters I posted. How can I do that using a C# console application?
Parameters: filename, userid, password, type
For this you can simply use the "HttpWebRequest" and "HttpWebResponse" classes in .net.
Below is a sample console app I wrote to demonstrate how easy this is.
Enjoy!
Take a look at the
System.Net.WebClient
class, it can be used to issue requests and handle their responses, as well as to download files:http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx
http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.90).aspx
Insted of using System.Net.WebClient I would recommend to have a look on System.Net.Http.HttpClient which was introduced with net 4.5 and makes your life much easier.
Also microsoft recommends to use the HttpClient on this article
http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.90).aspx
An example could look like this:
Hope it helps