Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net HTTP响应何时完成?_.net_Sockets_Http_Http Headers - Fatal编程技术网

.net 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

为了便于学习,我正在.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 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