HTTP 1.1 20 second delay compared to HTTP 1.0
I've written a program in C that sends a HTTP 1.1 POST
request to a web server.
HTTP/1.1 200 OK
message, but then it takes another 20 seconds to get the FIN, ACK
packet, which I believe this is what causes recv
to return 0, specifying no more data.Causing my program to hang for 20ish seconds well it waits for the server to send the FIN, ACK
packet.
I've tested this with HTTP 1.0
, and there isn't a delay. So I think this is because HTTP 1.1
by default considers all connections as persistent connections
.
HTTP 1.1
and there's no delay, so I think i'm not doing something right.
One idea I had was instead of waiting for recv
to return 0, I should check if i'm at the end of the document some other way, but I can't think of any way to do this.
So if anyone could explain to me how I should be doing this? Thanks in advance.
HTTP 1.1 defaults to keep-alive connections while 1.0 does not. You can request a non-keep-alive by adding in the header
Connection: close
which instructs the server to close the connection as soon as it's complete.
精彩评论