Varun Varun - 1 year ago 122
C++ Question

File downloading without extension Socket Programming

I am working in socket programming with help of C++.And I have to write a code to download file.
My Http Header for this is :

char header[] = "HTTP/1.1 200 OK\r\nContent-Type:application/;Content-Disposition:attachment;filename:\"abc.xls\";Content-Length:14; \r\n\r\n";

but file get downloaded as "download" it does not have extension too.
I also tried this with

char header[] = "HTTP/1.1 200 OK\r\nContent-Type:application/octet-stream;Content-Disposition:attachment;filename:\"abc.xls\";Content-Length:14; \r\n\r\n";

but its not working.
Can anyone help me regarding this.?

Answer Source

The HTTP response header you've tried looks like this:

HTTP/1.1 200 OK

instead it should look like this

HTTP/1.1 200 OK

I recommend you study the relevant standards before trying to implement a protocol. In this case this is the HTTP standard (RFC 7230 and following RFC) and "Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)" (RFC 6266).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download