-
Receiving content
I use this code to receive the results of my HTTP request:
Code:
int l;
char abc[100000];
char p[1024];
while((l=recv(sock,p,1023,0))>0){
cout.write(p,l);
p[l] = '\0';
strcpy(abc,p);
}
It displays all the content, but after it had showed all the content it just hangs. Anything after that doesn't work. I removed unnecessary things but it still doesn't work correctly:
Code:
int l;
char p[1024];
while((l=recv(sock,p,1023,0))>0){
cout.write(p,l);
}
Why?
-
Well, if it uses HTTP 1.0, then the connection will close when the data is sent, so recv will return a -1, this should work just fine with your code. However, if you specify HTTP 1.1, the connection may remain open after the full data has been recieved and if the connection remains open, recv will block while waiting for more data. If this is the case, you need to read the Content-Length header and after the "\r\n\r\n" that separates the header from the data, you read Content-Length number of bytes only. I would suggest that you just specify "GET /whatever HTTP/1.0" as your request string.
-
Yes, I believe that's the problem.