开发者

How to send a HTTP "Bad Request" Response

开发者 https://www.devze.com 2022-12-27 20:12 出处:网络
I am writing a C program which needs to send back a HTTP Bad Response. This is what I write to socket.

I am writing a C program which needs to send back a HTTP Bad Response. This is what I write to socket.

HTTP/1.开发者_如何学C1 400 Bad Request\r\n
Connection: close\r\n
\r\n

My question is why the broswer still spinning (like appear it is still loading something? Am I missing header in the Http response? OR I miss something else?

Thank you.


Connection: close

does not close connection immediately - it just indicates, that connection will not be reused after current request - it is opposite of Connection: keep-alive. Try to include Content-Length: 0 to indicate that there is no content at all.

Or, just close your socket.


Are you actually closing the connection afterwards?

0

精彩评论

暂无评论...
验证码 换一张
取 消