次の方法で共有


HttpWebRequest.SendChunked プロパティ

インターネット リソースへセグメント単位でデータを送信するかどうかを示す値を取得または設定します。

Public Property SendChunked As Boolean
[C#]
public bool SendChunked {get; set;}
[C++]
public: __property bool get_SendChunked();public: __property void set_SendChunked(bool);
[JScript]
public function get SendChunked() : Boolean;public function set SendChunked(Boolean);

プロパティ値

インターネット リソースへセグメント単位でデータを送信する場合は true 。それ以外の場合は false 。既定値は false です。

例外

例外の種類 条件
InvalidOperationException 要求が GetRequestStreamBeginGetRequestStreamGetResponse 、または BeginGetResponse の各メソッドの呼び出しによって開始されました。

解説

SendChunkedtrue の場合、要求はセグメント単位でインターネット リソースにデータを送信します。インターネット リソースは、チャンク データの受信をサポートしている必要があります

GetRequestStream メソッド、 BeginGetRequestStream メソッド、 GetResponse メソッド、または BeginGetResponse メソッドの呼び出しによって要求を開始した後に SendChunked プロパティを変更すると、 InvalidOperationException がスローされます。

使用例

[Visual Basic, C#, C++] SendChunked プロパティを true に設定して、インターネット リソースにデータをセグメント単位で送信する例を次に示します。

 
' A new 'HttpWebRequest' object is created.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
myHttpWebRequest.SendChunked = True
' 'TransferEncoding' property is set to 'gzip'.
myHttpWebRequest.TransferEncoding = "gzip"
Console.WriteLine(ControlChars.Cr + "Please Enter the data to be posted to the (http://" + ChrW(60) + "machine name" + ChrW(62) + "/CodeSnippetTest.asp) uri:")
Dim inputData As String = Console.ReadLine()
Dim postData As String = "testdata" + ChrW(61) + inputData
' 'Method' property of 'HttpWebRequest' class is set to POST.
myHttpWebRequest.Method = "POST"
Dim encodedData As New ASCIIEncoding()
Dim byteArray As Byte() = encodedData.GetBytes(postData)
' 'ContentType' property of the 'HttpWebRequest' class is set to "application/x-www-form-urlencoded".
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
' 'ContentLength' property is set to Length of the data to be posted.
myHttpWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()
Console.WriteLine(ControlChars.Cr + "Data has been posted to the Uri" + ControlChars.Cr + ControlChars.Cr + "Please wait for the response..........")
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Displaying the contents of the page to the console
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
Console.WriteLine(ControlChars.Cr + "The contents of the HTML page are :  ")
While count > 0
    Dim outputData As New [String](readBuff, 0, count)
    Console.WriteLine(outputData)
    count = streamRead.Read(readBuff, 0, 256)
End While
' Release the response object resources.  
streamRead.Close()
streamResponse.Close()
myHttpWebResponse.Close()

[C#] 
// A new 'HttpWebRequest' object is created.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
myHttpWebRequest.SendChunked=true;
// 'TransferEncoding' property is set to 'gzip'.
myHttpWebRequest.TransferEncoding="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.
myHttpWebRequest.Method="POST";
ASCIIEncoding encodedData=new ASCIIEncoding();
byte[]  byteArray=encodedData.GetBytes(postData);
// 'ContentType' property of the 'HttpWebRequest' class is set to "application/x-www-form-urlencoded".
myHttpWebRequest.ContentType="application/x-www-form-urlencoded";
// 'ContentLength' property is set to Length of the data to be posted.
myHttpWebRequest.ContentLength=byteArray.Length;
Stream newStream=myHttpWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);
newStream.Close();
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);
   Console.WriteLine(outputData);
   count = streamRead.Read(readBuff, 0, 256);
}
// Release the response object resources.
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close(); 

[C++] 
// A new 'HttpWebRequest' object is created.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(myUri));
myHttpWebRequest->SendChunked = true;
// 'TransferEncoding' property is set to 'gzip'.
myHttpWebRequest->TransferEncoding = S"gzip";
Console::WriteLine(S"\nPlease Enter the data to be posted to the (http://<machine name>/CodeSnippetTest::asp) uri:");
String* inputData = Console::ReadLine();
String* postData=String::Concat(S"testdata= ", inputData);
// 'Method' property of 'HttpWebRequest' class is set to POST.
myHttpWebRequest->Method = S"POST";
ASCIIEncoding* encodedData = new ASCIIEncoding();
Byte byteArray[] = encodedData->GetBytes(postData);
// 'ContentType' property of the 'HttpWebRequest' class is set to S"application/x-www-form-urlencoded".
myHttpWebRequest->ContentType = S"application/x-www-form-urlencoded";
// 'ContentLength' property is set to Length of the data to be posted.
myHttpWebRequest->ContentLength = byteArray->Length;
Stream* newStream = myHttpWebRequest->GetRequestStream();
newStream->Write(byteArray, 0, byteArray->Length);
newStream->Close();
Console::WriteLine(S"\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 =
   dynamic_cast<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(S"\nThe contents of the HTML page are :  ");
while (count > 0) {
   String* outputData = new String(readBuff, 0, count);
   Console::WriteLine(outputData);
   count = streamRead->Read(readBuff, 0, 256);
}
// Release the response object resources.
streamRead->Close();
streamResponse->Close();
myHttpWebResponse->Close();

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

HttpWebRequest クラス | HttpWebRequest メンバ | System.Net 名前空間