SendChunked Property

HttpWebRequest.SendChunked Property


Gets or sets a value that indicates whether to send data in segments to the Internet resource.

Namespace:   System.Net
Assembly:  System (in System.dll)

public bool SendChunked { get; set; }

Property Value

Type: System.Boolean

true to send data to the Internet resource in segments; otherwise, false. The default value is false.

Exception Condition

The request has been started by calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method.

When SendChunked is true, the request sends data to the Internet resource in segments. The Internet resource must support receiving chunked data.

Changing the SendChunked property after the request has been started by calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method throws an InvalidOperationException.

Legacy Code Example

The following code example sets the SendChunked property to true so that data can be sent in segments to the Internet resource.

// A new 'HttpWebRequest' object is created.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
// 'TransferEncoding' property is set to 'gzip'.
Console.WriteLine("\nPlease Enter the data to be posted to the (http://<machine name>/CodeSnippetTest.asp) uri:");
string inputData =Console.ReadLine();
string postData="testdata="+inputData;
// 'Method' property of 'HttpWebRequest' class is set to POST.
ASCIIEncoding encodedData=new ASCIIEncoding();
byte[]  byteArray=encodedData.GetBytes(postData);
// 'ContentType' property of the 'HttpWebRequest' class is set to "application/x-www-form-urlencoded".
// 'ContentLength' property is set to Length of the data to be posted.
Stream newStream=myHttpWebRequest.GetRequestStream();
Console.WriteLine("\nData has been posted to the Uri\n\nPlease wait for the response..........");
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
// Displaying the contents of the page to the console
Stream streamResponse=myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader( streamResponse );
Char[] readBuff = new Char[256];
int count = streamRead.Read( readBuff, 0, 256 );
Console.WriteLine("\nThe contents of the HTML page are :  ");
while (count > 0) 
   String outputData = new String(readBuff, 0, count);
   count = streamRead.Read(readBuff, 0, 256);
// Release the response object resources.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft