it sounds like your problem lies in your GET request. Have you looked at the HTTP keyword "HEADERS" e.t. GET / HTTP/1.1 HEADERS. In any case you have made no references or statements that imply this is a C++ question.
I would do a strlen() of buffer to get the buffer size for the write call
write(socket_fd, buffer, strlen(buffer));
You are writing a full 4096 bytes including whatever is in your buffer after the GET string.
If you are reading a complete file is the read of 4096 enough or too much? I don't know how big the image data is.
Read will, by default block until, in your case it gets a full 4096 bytes. If what you are trying to read is not that big it will hang on this call. I would set the socket to non-blocking and pick up the read return value to see how much data it read in. Look at the man page for details of this and fcntl() for setting non-blocking.
If you don't know the size of the data to read or if you use a non-blocking socket then really the read call should be in a loop. Control the loop by the read return value, and make sure the buffer(s) can cope.
Well, I used strlen but I take such as warning. This is not dangerouse?
get_http.c:27: warnind: incompatible implicit declaration of built-in function 'strlen'
I don't tink, why code listen below geting only http-header without image file.
Like a BUFSIZ is long, or not?
First of all add #include <string.h> to get rid of the warning. That warning is to tell you the compiler doesn't know if you are passing the correct parameters to strlen().
I've compiled and run your code, and there is nothing wrong with it. I got the following response
HTTP/1.1 400 Bad Request
Date: Sat, 31 May 2008 08:02:43 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 304
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at cplusplus.com Port 80</address>
</body></html>
You're sending an invalid request so it's not the code that is the problem
Yeah, I'm is understand in this. And I've is not problems to get a plain-text over by http request. I don't take just the image. I'm tray to get in again the image and detect GIF89a╪
How to any way parse this request and get only line into GIF89a╪? On unix-shell to use grep while on c++?
1 2 3 4 5 6 7 8 9 10 11 12
HTTP/1.1 200 OK
Content-Length: 1470
Content-Type: image/gif
Last-Modified: Thu, 10 Apr 2008 20:24:48 GMT
Accept-Ranges: bytes
ETag: "384425ec489bc81:589a"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Sat, 31 May 2008 16:15:00 GMT
Connection: close
GIF89a╪
There are a few things you could do but I think the most obvious one would be to put the above text in a std::string and use the member methods to extract what you want, maybe something like the example in http://www.cplusplus.com/reference/string/string/substr.html
Thanks!
I has a lot of one yet question. How to transport be cut buffer next method.
fwrite(buffer2 + i, 1, sz - i, pFile);
I'll hope to take inside pFile without reading a file. I want buffer3 with include 'buffer2 + i, 1, sz - i' value. The buffer3 should be string.
Please c, non c++ sample, without iostream to use.
_____
Thank in adv!
In that case use strstr() to find 'GIF' then search a character at a time until you get to the end of line, a space or whatever marks the end of what you want. Then put it all together to make the string you want.