xNejX
asked on
Download a file c++ with SOCKET
Hi Guys,
I'm trying to download a file using a SOCKET in C++. I have a problem because my code returns an HTTP response instead downloading the file at that location.
My return and the content of my "test.exe" is this:
How can I get the return to be the content of the file instead a HTTP/1.0 200 OK so I can write it (download it) to my local file?
Is the "GET" in my request wrong? Should i use a different request?
It needs to use the SOCKET method in order for me to be able to use a proxy server to download this file.
Thank you
I'm trying to download a file using a SOCKET in C++. I have a problem because my code returns an HTTP response instead downloading the file at that location.
WSADATA WSAData; WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKET sock; SOCKADDR_IN sin;
char buffer[1024];
std::string srequete (GET http://www.test.com/test.exe HTTP/1.1\r\n");
srequete += "Host: www.test.com\r\n";
srequete += "Connection: close\r\n";
srequete += "Keep-Alive: 115\r\n";
srequete += "Referer: http://www.test.com/\r\n";
srequete += "\r\n";c
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr("xxx.yyy.www.zz");
sin.sin_family = AF_INET;
sin.sin_port = htons(80);
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
send(sock, srequete.c_str(), srequete.length(), 0);
i = recv(sock, buffer, sizeof(buffer), 0);
fstream filestr;
filestr.open("Download/test.exe", fstream::in | fstream::out | fstream::app);
filestr << buffer << endl;
filestr.close();
closesocket(sock);
WSACleanup();
My return and the content of my "test.exe" is this:
HTTP/1.0 200 OK
Date: Mon, 22 Nov 2010 12:05:28 GMT
Server: Apache
Content-Disposition: attachment; filename=test.exe
Content-Length: 5884016
Content-Type: application/msi
X-Cache: MISS from ip-xxx-yyy-www-zz.ip.test.net
X-Cache-Lookup: MISS from ip-xxx-yyy-www-zz.ip.test.net:80
Via: 1.0 ip-xxx-yyy-www-zz.ip.test.net (squid/3.1.7)
Connection: keep-alive
MZ
How can I get the return to be the content of the file instead a HTTP/1.0 200 OK so I can write it (download it) to my local file?
Is the "GET" in my request wrong? Should i use a different request?
It needs to use the SOCKET method in order for me to be able to use a proxy server to download this file.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, thank you.
You're welcome - I'm glad I could help ...
have a nice day,
best regards,
ZOPPO
have a nice day,
best regards,
ZOPPO
ASKER