WebClient.Encoding Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
A Encoding that is used to encode strings. The default value of this property is the encoding returned by Default.
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);
// Display 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
Forsiktig
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
The UploadString and UploadStringAsync methods use this property to convert the specified string to a Byte array before uploading the string. For additional information, see the GetBytes method.
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. For additional information, see the GetString method.
Produkt | Versjoner |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET-tilbakemelding
.NET er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding: