HttpRequest.GetBufferlessInputStream 方法

定义

获取一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。Gets a Stream object that can be used to read the incoming HTTP entity body.

重载

GetBufferlessInputStream()

获取一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。Gets a Stream object that can be used to read the incoming HTTP entity body.

GetBufferlessInputStream(Boolean)

获取能被用于读取正在到来的 HTTP 实体正文的 Stream 对象,同时随意地禁止设置在 MaxRequestLength 属性中的请求长度限制。Gets a Stream object that can be used to read the incoming HTTP entity body, optionally disabling the request-length limit that is set in the MaxRequestLength property.

GetBufferlessInputStream()

获取一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。Gets a Stream object that can be used to read the incoming HTTP entity body.

public:
 System::IO::Stream ^ GetBufferlessInputStream();
public System.IO.Stream GetBufferlessInputStream ();
member this.GetBufferlessInputStream : unit -> System.IO.Stream
Public Function GetBufferlessInputStream () As Stream

返回

一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。A Stream object that can be used to read the incoming HTTP entity body.

异常

已加载和分析请求的实体主体。The request's entity body has already been loaded and parsed. 导致加载和分析实体正文的属性的示例包括:Examples of properties that cause the entity body to be loaded and parsed include the following:

要避免此异常,请首先调用 ReadEntityBodyMode 方法。To avoid this exception, call the ReadEntityBodyMode method first. 如果客户在实体正文读取时断开连接,则也会引发此异常。This exception is also thrown if the client disconnects while the entity body is being read.

注解

此方法提供使用InputStream属性的替代方法。This method provides an alternative to using the InputStream property. 属性InputStream将等待,直到收到整个请求后再Stream返回对象。The InputStream property waits until the whole request has been received before it returns a Stream object. 与此GetBufferlessInputStream相反,方法会立即Stream返回对象。In contrast, the GetBufferlessInputStream method returns the Stream object immediately. 您可以使用方法来开始处理实体正文,然后再接收正文的完整内容。You can use the method to begin processing the entity body before the complete contents of the body have been received.

仅当您使用由此方法返回的对象通过调用方法(如Read方法)来读取流时,才会返回实体主体(或根据您的需要,也就是收到的内容)。The entity body (or as much of it as you request and has been received) is returned only when you use the object that is returned by this method to read the stream, by calling methods such as the Read method. 使用Read方法的参数指定要读取的实体正文的数量。You use parameters of the Read method to specify how much of the entity body to read.

ASP.NET Stream从此方法返回的对象支持同步和异步读取方法。The Stream object returned by ASP.NET from this method supports both synchronous and asynchronous read methods. 对象同时实现EndRead和方法。 BeginRead StreamThe Stream object implements both the BeginRead and EndRead methods. 使用异步方法,你可以在块中异步读取请求实体,而 ASP.NET 将在异步读取循环的每次迭代之间释放当前线程。The asynchronous methods let you asynchronously read the request entity in chunks, while ASP.NET releases the current thread in between each iteration of an asynchronous read loop.

此方法在以下情况下很有用:请求正在上传大型文件,并且想要在上传完成前访问文件内容。This method can be useful if the request is uploading a large file and you want to begin accessing the file contents before the upload is finished. 但是,只应将此方法用于需要接管实体正文的所有处理的方案。However, you should only use this method for scenarios where you want to take over all processing of the entity body. 这意味着不能从 .aspx 页面使用此方法,因为 .aspx 页面运行时,实体正文已被读取。This means that you cannot use this method from an .aspx page, because by the time an .aspx page runs, the entity body has already been read.

另请参阅

GetBufferlessInputStream(Boolean)

获取能被用于读取正在到来的 HTTP 实体正文的 Stream 对象,同时随意地禁止设置在 MaxRequestLength 属性中的请求长度限制。Gets a Stream object that can be used to read the incoming HTTP entity body, optionally disabling the request-length limit that is set in the MaxRequestLength property.

public:
 System::IO::Stream ^ GetBufferlessInputStream(bool disableMaxRequestLength);
public System.IO.Stream GetBufferlessInputStream (bool disableMaxRequestLength);
member this.GetBufferlessInputStream : bool -> System.IO.Stream
Public Function GetBufferlessInputStream (disableMaxRequestLength As Boolean) As Stream

参数

disableMaxRequestLength
Boolean

使请求长度限制失去意义,则为 true;否则为 falsetrue to disable the request-length limit; otherwise, false.

返回

一个 Stream 对象,该对象可用于读取传入的 HTTP 实体主体。A Stream object that can be used to read the incoming HTTP entity body.

异常

已加载和分析请求的实体主体。The request's entity body has already been loaded and parsed. 导致加载和分析实体正文的属性的示例包括:Examples of properties that cause the entity body to be loaded and parsed include the following: - Form 属性。- The Form property.

- Files 属性。- The Files property.

- InputStream 属性。- The InputStream property.

- GetBufferedInputStream() 方法。- The GetBufferedInputStream() method.

要避免此异常,请首先调用 ReadEntityBodyMode 方法。To avoid this exception, call the ReadEntityBodyMode method first. 如果客户在实体正文读取时断开连接,则也会引发此异常。This exception is also thrown if the client disconnects while the entity body is being read.

注解

有关此方法的详细信息,请参阅GetBufferlessInputStream()重载。For more information about this method, see the GetBufferlessInputStream() overload.

另请参阅

适用于