Get and set the Encoding used to upload and download strings in CSharp

Description

The following code shows how to get and set the Encoding used to upload and download strings.

Example


using System;/*from w w  w  .  j a v a  2  s .c  o m*/
using System.Net;
using System.Net.Sockets;

public class Example
{
   public static void Main()
   {
        string data = "myData= 50";
        WebClient client = new WebClient ();

        client.Encoding = System.Text.Encoding.UTF8;

        string reply = client.UploadString ("http://cnn.com", data);

        Console.WriteLine (reply);
    
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client