Sending images via HTTP
Hi all, problems with this darn web server I'm making once again.
I'm trying to get it to send images. Problem is, I can't quite figure out how to do it. I send the headers:
Just like google uses, and then I send the contents of the file. Unfortunately I am stumped because it never works :(
I started by opening the file and using getline() to read in each line and send it to the browser, but that didn't work.
So then I tried opening the file in binary, and using getline, still to no avail.
Then, I opened it in binary and used the read() function to read it in binary too, but still it failed to work.
Each time I tried, the page displayed in the browser was the text version of everything I had sent, as in it had each of the headers as well as the information of the image all printed as if it was a text file :(
Does anyone have any suggestions as to why this is happening, or have any links to sites that teach how to do things like this? I would very much appreciate them.
Edit: This is the code I have:
Also, I think a problem could be that even if I read in binary, the send() socket function could be sending it as plain text.... could that be right?
// Open the file and read output
ifstream openFile(FileStr.c_str(), ios::binary);
while (openFile.read(Buffer, 10000))
Content += Buffer;
send(SocketDescriptor, Content.c_str(), Content.Length(), 0);
Edit2: I fixed the problem so that it doesn't display on the screen as text, so now theres a Square with a red cross in it instead (to show theres an image but theres something wrong with it).