如何使用C Socket编程下载文件 [英] How can I download a file using C Socket Programming
本文介绍了如何使用C Socket编程下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何制作类似Internet Download Manager的程序来从Internet下载给定链接的文件。可以使用套接字编程C从Internet下载文件。
How can i make a program like internet download manager to download a file of given link from internet. Could use socket programming C to download a file from internet.
我们将为您提供帮助。
谢谢。
Your help will be appreciated. Thanks.
推荐答案
- 使用
socket()$ c $创建套接字c>
- 在其上调用
connect()
。 - 发送
使用
请求code> write()正确。send()
或<>获取/ path / filename HTTP / 1.0\r\n\r\n - 使用
recv()
或read()
正确。 - 解析响应,以了解请求是否成功以及文件数据的发送格式。
- 使用
recv()
或read()$接收文件数据(如果存在) c $ c>。
- 使用
close()
关闭套接字。
- Create a socket using
socket()
- Call
connect()
on it. - Send a
GET /path/filename HTTP/1.0\r\n\r\n
request using eithersend()
orwrite()
properly. - Receive the response using either
recv()
orread()
properly. - Parse the response to find out if the request succeeded and what format the file data is being sent as.
- Receive the file data, if present, using either
recv()
orread()
. - Close the socket using
close()
.
其他读数:
- http://tools.ietf.org/html/rfc7230#section-2.1
- http://unpbook.com
这篇关于如何使用C Socket编程下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文