Hello everybody.
I would like to know how to download and save a file to my hard drive, specifically a zip file from a HTTP server using the System.Net.Socket.Sockets class.
I know there are allot easier ways to download a file with .Net, but i would like to know how to do it with Sockets, if possible of course although I'm pretty sure it is.
I've tried a few things, nothing worked once i don't have any background experience with sockets.
Your help satisfying my curiosity is appreciated. Any question just ask. Thank you.
Note:
You could do this directly with a .NET socket, but it would require parsing and understanding the HTTP request.
The standard way to do this would just be to use the higher level System.Net classes. For example, this can be done in two lines of code via WebClient.DownloadFile - why make life more difficult for yourself?
If you really must do this from raw sockets, it will just take a lot of work. At it's core, you can connect to port 80 (assuming http) via a TCP connection, write the correct strings to the socket, and start receiving data.
That being said, getting everything correct, and handling all of the issues required is far beyond a standard StackOverflow answer's scope. If you want to go down this road, take a look at the HTTP Protocol specifications - you'll need to implement the proper aspects of this specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With