HttpRequest.GetBufferlessInputStream 方法

定義

取得可用來讀取傳入 HTTP 實體內容的 Stream 物件。Gets a Stream object that can be used to read the incoming HTTP entity body.

多載

GetBufferlessInputStream()

取得可用來讀取傳入 HTTP 實體內容的 Stream 物件。Gets a Stream object that can be used to read the incoming HTTP entity body.

GetBufferlessInputStream(Boolean)

取得 Stream 物件,這個物件可用來讀取傳入 HTTP 實體內容,並選擇性地停用 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()

取得可用來讀取傳入 HTTP 實體內容的 Stream 物件。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

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.

備註

這個方法會提供使用屬性的替代方法 InputStreamThis 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.

當您要求和收到的實體主體 (或最多時,只有當您透過呼叫方法(例如方法)使用這個方法所傳回的物件來讀取資料流程時,才會傳回) 。 ReadThe 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.

StreamASP.NET 從這個方法傳回的物件支援同步和非同步 read 方法。The Stream object returned by ASP.NET from this method supports both synchronous and asynchronous read methods. Stream物件會同時執行 BeginReadEndRead 方法。The 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)

取得 Stream 物件,這個物件可用來讀取傳入 HTTP 實體內容,並選擇性地停用 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

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.

另請參閱

適用於