.net HTTP响应何时完成?
为了便于学习,我正在.NET中编写一个简单的HTTP客户端。我使用的是.NET类,它最终使用。我不想像他们使用的那样使用,也不想像他们使用的那样使用,因为我这样做是为了理解HTTP的工作原理 我想知道如何确定HTTP响应何时完成。通过阅读HTTP/1.1规范(),我认为下面的伪代码是如何确定HTTP响应何时完成的.net HTTP响应何时完成?,.net,sockets,http,http-headers,.net,Sockets,Http,Http Headers,为了便于学习,我正在.NET中编写一个简单的HTTP客户端。我使用的是.NET类,它最终使用。我不想像他们使用的那样使用,也不想像他们使用的那样使用,因为我这样做是为了理解HTTP的工作原理 我想知道如何确定HTTP响应何时完成。通过阅读HTTP/1.1规范(),我认为下面的伪代码是如何确定HTTP响应何时完成的 parse HTTP headers if parse not successful: throw error if HTTP version is 1.1 and Trans
parse HTTP headers
if parse not successful:
throw error
if HTTP version is 1.1 and Transfer-encoding is chunked:
parse first line of each chunk as an ASCII hexadecimal, the chunk size
if parse not successful:
throw error
read each chunk until chunk size 0
else if Content-Length is specified:
read Content-Length number of bytes
else:
throw error
这是一种或多或少正确的方法吗?您应该看一下(如果这不能回答您的问题,请发回工作组)。您应该看一下(如果这不能回答您的问题,请发回工作组)。您的理解基本正确,但有一些小的更正,具体如下:
您的理解基本上是正确的,但有一些小的更正,根据: 可能的重复的见RFC 2616(4.4)()更多的情况考虑。可能重复的见RFC 2616(4.4)()更多的情况下考虑。
Read and parse HTTP headers
if not successful:
throw error
if response can contain message body:
if HTTP version is 1.1+ and Transfer-encoding is not identity:
while true:
read line, extract delimited ASCII hexadecimal, the chunk size
if not successful:
throw error
if chunk size is 0:
break while loop
read chunk size number of bytes
read and parse trailing HTTP headers
else if Content-Length is specified:
read Content-Length number of bytes
else if Content-Type is "multipart/byteranges":
read and parse MIME-encoded chunks until terminating MIME boundary is reached
else:
read until connection is closed