这是我的阅读网页。在c#语言中。
但是当我执行它时它有一些例外。有人知道为什么吗?
try
{
string address = "http://" + txtMsg.Text;
int port = int.Parse(textBox1.Text);
System.Net.WebClient webclient = new WebClient();
String content = webclient.DownloadString(address);
Socket skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
skt.Connect(address, port);
string hdrs = "GET " + address + ":" + port + " HTTP/1.1\r\n"
+ "Host: " + address + ":" + port + "\r\n";
byte[] req_as_bytes = Encoding.UTF8.GetBytes(hdrs);
skt.Send(req_as_bytes);
byte[] data = new byte[1024 * 200];
int t = skt.Receive(data);
lstMsg.Items.Add(Encoding.UTF8.GetString(data, 0, t));
skt.Shutdown(SocketShutdown.Both);
skt.Close();
btnConnect.Text = "done";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}