HttpListenerRequest.HasEntityBody 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 Boolean 值,该值指示请求是否有关联的正文数据。
public:
property bool HasEntityBody { bool get(); };
public bool HasEntityBody { get; }
member this.HasEntityBody : bool
Public ReadOnly Property HasEntityBody As Boolean
属性值
如果请求有关联的正文数据,则为 true
;否则为 false
。
示例
下面的代码示例演示如何使用此属性。
public static void ShowRequestData (HttpListenerRequest request)
{
if (!request.HasEntityBody)
{
Console.WriteLine("No client data was sent with the request.");
return;
}
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = request.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
if (request.ContentType != null)
{
Console.WriteLine("Client data content type {0}", request.ContentType);
}
Console.WriteLine("Client data content length {0}", request.ContentLength64);
Console.WriteLine("Start of client data:");
// Convert the data to a string and display it on the console.
string s = reader.ReadToEnd();
Console.WriteLine(s);
Console.WriteLine("End of client data:");
body.Close();
reader.Close();
// If you are finished with the request, it should be closed also.
}
Public Shared Sub ShowRequestData(ByVal request As HttpListenerRequest)
If Not request.HasEntityBody Then
Console.WriteLine("No client data was sent with the request.")
Return
End If
Dim body As System.IO.Stream = request.InputStream
Dim encoding As System.Text.Encoding = request.ContentEncoding
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(body, encoding)
If request.ContentType IsNot Nothing Then
Console.WriteLine("Client data content type {0}", request.ContentType)
End If
Console.WriteLine("Client data content length {0}", request.ContentLength64)
Console.WriteLine("Start of client data:")
' Convert the data to a string and display it on the console.
Dim s As String = reader.ReadToEnd()
Console.WriteLine(s)
Console.WriteLine("End of client data:")
body.Close()
reader.Close()
' If you are finished with the request, it should be closed also.
End Sub
注解
例如,使用 POST
方法将数据发送到服务器的请求应具有实体正文。