如何使用C Socket编程下载文件 [英] How can I download a file using C Socket Programming

查看:105
本文介绍了如何使用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.

推荐答案


  1. 使用 socket()

  2. 在其上调用 connect()

  3. 发送使用 send()或<>获取/ path / filename HTTP / 1.0\r\n\r\n 请求code> write()正确。

  4. 使用 recv() read()正确。

  5. 解析响应,以了解请求是否成功以及文件数据的发送格式。

  6. 使用 recv() read()

  7. 使用 close()关闭套接字。

  1. Create a socket using socket()
  2. Call connect() on it.
  3. Send a GET /path/filename HTTP/1.0\r\n\r\n request using either send() or write() properly.
  4. Receive the response using either recv() or read() properly.
  5. Parse the response to find out if the request succeeded and what format the file data is being sent as.
  6. Receive the file data, if present, using either recv() or read().
  7. Close the socket using close().

其他读数:

  • http://tools.ietf.org/html/rfc7230#section-2.1
  • http://unpbook.com

这篇关于如何使用C Socket编程下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆