zoukankan      html  css  js  c++  java
  • WebRequest类: WebRequest类是.NET.Framework的请求/响应模型的抽象基类,用于访问Internet数据

    WebRequest类:

    WebRequest类是.NET.Framework的请求/响应模型的抽象基类,用于访问Internet数据


    WebResponse类:

    也是抽象基类。

    客户端应用程序不直接创建WebResponse对象,而是通过对WebRequest实例调用GetResponse方法来进行创建。


    StreamReader:
    实现一个 TextReader,使其以一种特定的编码从字节流中读取字符。


    ReadToEnd();
    读取来自流的当前位置到结尾的所有字符。


    //正则表达式判断是否为正确的网址
    return System.Text.RegularExpressions.Regex.IsMatch(input, "http(s)?://([\w+\.])+[\w-]+(//[\w-.//?%&=]*)?");

    //例题

    获取网页源代码

    public bool Validatedata(string input)
    {
    return System.Text.RegularExpressions.Regex.IsMatch(input, "http(s)?://([\w+\.])+[\w-]+(//[\w-.//?%&=]*)?");
    }

    private void button1_Click(object sender, EventArgs e)
    {
    if (say(this.textBox1.Text))
    {
    //WebRequest类是.NET.Framework的请求/响应模型的抽象基类,用于访问Internet数据

    //实例化一个WebRequest对象
    WebRequest rq = WebRequest.Create(textBox1.Text);
    WebResponse rs = rq.GetResponse();//创建webresponse对象
    Stream st = rs.GetResponseStream();//调用WebResponse对象的GetResponseStream方法返回数据流
    //使用创建的Stream对象创建一个StreamReader流读取对象
    StreamReader reader = new StreamReader(st);
    string text = reader.ReadToEnd();// //读取流中的内容,并显示在RichTestBox控件中
    this.richTextBox1.Text = text;
    }
    else
    {
    this.textBox1.Text = "";
    MessageBox.Show("请输入正确的网址!","温馨提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }

    }

  • 相关阅读:
    3.19 DAY2
    3.18 DAY1
    MySql Scaffolding an Existing Database in EF Core
    asp.net core 2.0 后台定时自动执行任务
    c#中枚举类型 显示中文
    fullCalendar使用经验总结
    Web APP 日期选择控件
    【转】剖析异步编程语法糖: async和await
    【转】Entity Framework 复杂类型
    【转】EF Code First 学习笔记:约定配置
  • 原文地址:https://www.cnblogs.com/tdmins/p/9845632.html
Copyright © 2011-2022 走看看