Thread: Sending images via HTTP

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    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:
    Content-Type: image/jpeg
    Connection: keep-alive

    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:
    PHP Code:
    // Open the file and read output
    ifstream openFile(FileStr.c_str(), ios::binary);
    char Buffer[10000];
    AnsiString Content;
    while (
    openFile.read(Buffer10000))
    {
           
    Content += Buffer;
    }
    openFile.close();
    send(SocketDescriptorContent.c_str(), Content.Length(), 0); 
    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?

    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).
    Last edited by nickname_changed; 05-23-2003 at 08:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error stop Http Listener
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-04-2008, 02:14 AM
  2. Sending an http POST request
    By jaxen in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2006, 12:35 PM
  3. sending HTTP POST data with Socket
    By Overtaker in forum Networking/Device Communication
    Replies: 10
    Last Post: 09-07-2006, 10:11 AM
  4. Sending http request to httpd
    By Encrypted in forum C Programming
    Replies: 3
    Last Post: 03-30-2003, 04:57 AM