WebRequest.ContentType WebRequest.ContentType WebRequest.ContentType WebRequest.ContentType Property

定义

当在子类中被重写时,获取或设置所发送的请求数据的内容类型。When overridden in a descendant class, gets or sets the content type of the request data being sent.

public:
 virtual property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };
public virtual string ContentType { get; set; }
member this.ContentType : string with get, set
Public Overridable Property ContentType As String

属性值

请求数据的内容类型。The content type of the request data.

异常

当未在子类中重写该属性时,试图获取或设置该属性。Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

示例

下面的示例将ContentType属性设置为适当的媒体类型。The following example sets the ContentType property to the appropriate media type.

// Set the 'ContentType' property of the WebRequest.
myWebRequest->ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest->ContentLength = byteArray->Length;
Stream^ newStream = myWebRequest->GetRequestStream();
newStream->Write( byteArray, 0, byteArray->Length );

// Close the Stream object.
newStream->Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType="application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength=byteArray.Length;
Stream newStream=myWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);

// Close the Stream object.
newStream.Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();



' Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)

' Close the Stream object.
newStream.Close()

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

注解

ContentType属性包含请求的媒体类型。The ContentType property contains the media type of the request. 这通常是内容的 MIME 编码。This is typically the MIME encoding of the content.

备注

类是一个abstract类。 WebRequestThe WebRequest class is an abstract class. WebRequest实例在运行时的实际行为由WebRequest.Create方法返回的子代类确定。The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. 有关默认值和异常的详细信息,请参阅子代类的文档,例如HttpWebRequest和。 FileWebRequestFor more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

适用于

另请参阅