0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dotNet > WebClient() > Encoding指定 > new時の指定 / プロパティ指定

Last updated at Posted at 2015-11-04

WebClient()を使う時にEncodingを指定する方法

new時に指定

引用: 即効入門 C#プログラミング すぐに現場で使える知識 by 中 博俊さんら
3.2 Webアクセスのためのクラス

文字コードを明示的に指定する例

// たとえば、MSDN は UTF-8
var url = "http://msdn.microsoft.com/ja-JP/";

var c = new WebClient { Encoding = Encoding.UTF8 };
var x = c.DownloadString(url);

プロパティを指定

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);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?