using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
namespace HttpEx {
public partial class HttpForm : Form {
//コンストラクタ
public HttpForm() {
InitializeComponent();
}
//読み込みボタンのイベント処理
private void btnRead_Click(object sender, EventArgs e) {
try {
tbText.Text=LoadText("http://npaka.net/HttpEx/test.txt");
} catch (Exception exc) {
MessageBox.Show(exc.ToString(),"エラー");
}
}
//テキストの読み込み
private String LoadText(String url) {
HttpWebRequest req=WebRequest.Create(url) as HttpWebRequest;
HttpWebResponse res=req.GetResponse() as HttpWebResponse;
StreamReader reader=new StreamReader(res.GetResponseStream(),
Encoding.GetEncoding("Shift_JIS"));
String result=reader.ReadToEnd();
reader.Close();
return result;
}
}
}
|