Bagikan melalui


HttpWebRequest.Accept Properti

Definisi

Mendapatkan atau mengatur nilai Accept header HTTP.

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

Nilai Properti

Nilai Accept header HTTP. Nilai defaultnya adalah null.

Contoh

Contoh kode berikut mengatur Accept properti .

// Create a 'HttpWebRequest' object.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
// Set the 'Accept' property to accept an image of any type.
myHttpWebRequest.Accept="image/*";
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
' Create a 'HttpWebRequest' object.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(myUri)
' Set the 'Accept' property to accept an image of any type.
myHttpWebRequest.Accept = "image/*"
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

Keterangan

Hati

WebRequest, , HttpWebRequestServicePoint, dan WebClient usang, dan Anda tidak boleh menggunakannya untuk pengembangan baru. Gunakan HttpClient sebagai gantinya.

Untuk menghapus Accept header HTTP, atur properti ke Acceptnull.

Nota

Nilai untuk properti ini disimpan dalam WebHeaderCollection. Jika WebHeaderCollection diatur, nilai properti akan hilang.

Berlaku untuk