- #include <string>
- #include <iostream>
- #include <stdio.h>
- #include <winsock.h>
- #include <conio.h>
- using namespace std;
- #pragma comment("ws2_32.lib")
- string host2ip(const string& strdomain);
- void save2file(char *buffer,const string& filename);
- int getlength(const string& sheader);
- bool getstatus(const string& sheader);
- int getleftlength(const string& sheader);
- void sethttphead(const string& file,const string& server);
- int port = 80;
- int error=0;
- string serveraddr;
- int i = 0;
- const int BUFFER_SIZE = 1024;
- char buffer[BUFFER_SIZE] = {0};
- char msg[BUFFER_SIZE];
- FILE *f;
- const string file = "/BT/200801/3/117906.torrent";
- const string url = "www.supbt.com";
- const string filename = "117906.torrent";
- int main(void)
- {
- int r;
- WSADATA wsa;
- SOCKET sock;
- struct sockaddr_in sin;
- f = fopen(filename.c_str(),"ab");
- sethttphead(file,url);
Linux下Socket写http协议下载文件代码以及说明
最新推荐文章于 2024-04-17 22:07:36 发布
本文展示了一段C++代码,使用Linux Socket编程实现在HTTP协议下从指定URL下载文件。代码包括设置HTTP头部,连接服务器,接收并保存文件内容等步骤。
摘要由CSDN通过智能技术生成