• winform 网络部分编程 ,浏览器,域名解析,下载网址内容


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    using System.Collections.Specialized;
    
    namespace myone
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
            //域名解析
            private void button1_Click(object sender, EventArgs e)
            {
                if(txtUrl.Text!=string.Empty)
                {
                    IPHostEntry host = Dns.GetHostEntry(txtUrl.Text);//获取url的主机名
                    foreach (IPAddress add in host.AddressList)//主机名的ip地址列表地址
                    {
                        long ip = add.Address;//主机名的ip
                        listBox1.Items.Add(add.ToString());//加地址  255.255.255.255格式
                        listBox1.Items.Add(ip.ToString());//加ip  long 格式
    
                    }
                    textName.Text = host.HostName;//主机名(域名代理的情况)
                    textBroad.Text = IPAddress.Broadcast.ToString();//广播地址
    
                }
                else
                {
                    MessageBox.Show("请输入网址!", "错误提示");
                }
    
    
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
    
            }
            //下载数据
            private void button3_Click(object sender, EventArgs e)
            {
                WebClient clent = new WebClient();//
                Stream s = clent.OpenRead(textBox1.Text);//url  必须是http://www.baidu.com    http://www.google.com.hk 
                StreamReader reader = new StreamReader(s);//
                richTextBox1.Text = reader.ReadToEnd();//显示
                reader.Close();
                s.Close();
    
            }
            //Header
            private void button4_Click(object sender, EventArgs e)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(textBox1.Text);
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                NameValueCollection headers = res.Headers;
                foreach(string name in headers)
                {
                    listBox1.Items.Add(name + "-----" + headers[name]);
                }
    
    
            }
            //连接到  Navigate航行,跳转
            private void button5_Click(object sender, EventArgs e)
            {
                textBox1.Text = "http://www.google.com.hk";
                webBrowser1.Navigate(textBox1.Text, false);
            }
        }
    }
    发现自己的不足,善于利用找到的方法去扬长避短。行动起来。
  • 相关阅读:
    C#使用WINDOW
    赵四小姐从十六岁开始跟张学良。跟一年,属奸情;跟三年,算偷情;跟六十年,便成为千古爱情!
    Microsoft Visual Studio 2010(VS2010)正式版 CDKEY / SN:
    C#中byte[]与string的转换
    sqlserver waitfor time '10:00' waitfor delay '1:00' 时间延时 和 间隔
    免费下载 精英讲解
    在决定使用ClickOnce发布你的软件前,应该知道的一些事情
    Windows7下注册OCX的注意事项
    用命令行以最快速简单的方式搭建MySQL数据库
    设计模式探索系列之Bridge模式
  • 原文地址:https://www.cnblogs.com/rechen/p/5113296.html
Copyright © 2020-2023  润新知