WebClient.Encoding WebClient.Encoding WebClient.Encoding WebClient.Encoding Property

Definition

Ruft die Encoding für den Up- und Download von Zeichenfolgen ab, oder legt diese fest.Gets or sets the Encoding used to upload and download strings.

public:
 property System::Text::Encoding ^ Encoding { System::Text::Encoding ^ get(); void set(System::Text::Encoding ^ value); };
public System.Text.Encoding Encoding { get; set; }
member this.Encoding : System.Text.Encoding with get, set
Public Property Encoding As Encoding

Eigenschaftswert

Eine Encoding zum Codieren von Zeichenfolgen.A Encoding that is used to encode strings. Der Standardwert dieser Eigenschaft ist die von Default zurückgegebene Codierung.The default value of this property is the encoding returned by Default.

Beispiele

Im folgenden Codebeispiel wird das Festlegen des Werts dieser Eigenschaft veranschaulicht.The following code example demonstrates setting the value of this property.

void UploadString( String^ address )
{
   String^ data = "Time = 12:00am temperature = 50";
   WebClient^ client = gcnew WebClient;
   
   // Optionally specify an encoding for uploading and downloading strings.
   client->Encoding = System::Text::Encoding::UTF8;
   
   // Upload the data.
   String^ reply = client->UploadString( address, data );
   
   // Disply the server's response.
   Console::WriteLine( reply );
}


public static void UploadString (string address)
{
    string data = "Time = 12:00am temperature = 50";
    WebClient client = new WebClient ();
    // Optionally specify an encoding for uploading and downloading strings.
    client.Encoding = System.Text.Encoding.UTF8;
    // Upload the data.
    string reply = client.UploadString (address, data);
    // Disply the server's response.
    Console.WriteLine (reply);
}

Public Shared Sub UploadString(ByVal address As String)

    Dim data As String = "Time = 12:00am temperature = 50"
    Dim client As WebClient = New WebClient()
    '  Optionally specify an encoding for uploading and downloading strings.
    client.Encoding = System.Text.Encoding.UTF8
    '  Upload the data.
    Dim reply As String = client.UploadString(address, data)
    '  Disply the server's response.
    Console.WriteLine(reply)
End Sub

Hinweise

Die Methoden UploadString und UploadStringAsync verwenden diese Eigenschaft, um die angegebene Zeichenfolge in ein Byte-Array zu konvertieren, bevor die Zeichenfolge hochgeladen wird.The UploadString and UploadStringAsync methods use this property to convert the specified string to a Byte array before uploading the string. Weitere Informationen finden Sie unter der GetBytes Methode.For additional information, see the GetBytes method.

Wenn eine Zeichenfolge mithilfe der Methoden DownloadString oder DownloadStringAsync heruntergeladen wird, verwendet WebClient den von diesem zurückgegebenen Encoding, um das heruntergeladene Byte-Array in eine Zeichenfolge zu konvertieren.When a string is downloaded using the DownloadString or DownloadStringAsync methods, WebClient uses the Encoding returned by this to convert the downloaded Byte array into a string. Weitere Informationen finden Sie unter der GetString Methode.For additional information, see the GetString method.

Gilt für: