C#でこのURLのhtmlファイルをダウンロードさせるとhtmlファイルが文字化けしています。
ダウンロードするのが問題なのかと思い、試しにダウンロードさせないでhtmlのソースを取得させてみましたが文字化けしていました。
解決法があれば教えていただきたいです。
宜しくお願い致します。
下のページに載っているコードを使いました。
- http://blog.codebook-10000.com/entry/20131001/1380648141
- https://www.ipentec.com/document/document.aspx?page=csharp-http-get-web-using-web-client
実際に使用してみたコード
htmlファイルをダウンロードするやり方
C#
1 private void Form1_Load(object sender, EventArgs e) 2 { 3 string outputHtml = @"C:\download.html"; 4 StreamWriter writer = new StreamWriter(outputHtml); 5 6 WebClient client = new WebClient(); 7 string str = client.DownloadString("https://pvp.minecraft.jp/servers"); 8 writer.Write(str); 9 }
htmlのソースを直接表示させるやり方
C#
1private void Form1_Load(object sender, EventArgs e) 2 { 3 WebClient wc = new WebClient(); 4 try 5 { 6 string text = wc.DownloadString("https://pvp.minecraft.jp/servers"); 7 textBox1.Text += text; 8 } 9 catch (WebException exc) 10 { 11 textBox1.Text += exc.Message; 12 } 13 14 this.MaximizeBox = !this.MaximizeBox; 15 timer1.Start(); 16 }
回答3件
あなたの回答
tips
プレビュー