Compartir a través de


HttpWebRequest.Accept Propiedad

Definición

Obtiene o establece el valor del encabezado HTTP de Accept.

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

Valor de propiedad

Valor del encabezado HTTP de Accept. El valor predeterminado es null.

Ejemplos

En el ejemplo de código siguiente se establece la propiedad Accept.

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

Comentarios

Cautela

WebRequest, HttpWebRequest, ServicePointy WebClient están obsoletos y no debe usarlos para el nuevo desarrollo. Use HttpClient en su lugar.

Para borrar el encabezado HTTP de Accept, establezca la propiedad Accept en null.

Nota

El valor de esta propiedad se almacena en WebHeaderCollection. Si se establece WebHeaderCollection, se pierde el valor de la propiedad.

Se aplica a