Bagikan melalui


WebRequest.ContentType Properti

Definisi

Saat ditimpa di kelas turunan, mendapatkan atau mengatur jenis konten data permintaan yang dikirim.

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

Nilai Properti

Jenis konten data permintaan.

Pengecualian

Setiap upaya dilakukan untuk mendapatkan atau mengatur properti, ketika properti tidak ditimpa di kelas turunan.

Contoh

Contoh berikut mengatur ContentType properti ke jenis media yang sesuai.

// 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()

Keterangan

Properti ContentType berisi jenis media permintaan. Ini biasanya pengodean MIME dari konten.

Catatan

Kelasnya WebRequest adalah kelas abstract . Perilaku WebRequest aktual instans pada durasi ditentukan oleh kelas turunan yang dikembalikan oleh WebRequest.Create metode . Untuk informasi selengkapnya tentang nilai dan pengecualian default, lihat dokumentasi untuk kelas turunan, seperti HttpWebRequest dan FileWebRequest.

Berlaku untuk

Lihat juga