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);
    }

    }

  • 相关阅读:
    Liberty Mutual Property Inspection, Winner's Interview: Qingchen Wang
    均方根值(RMS)+ 均方根误差(RMSE)+标准差(Standard Deviation)
    Comparing Differently Trained Models
    Stochastic Optimization Techniques
    Here’s just a fraction of what you can do with linear algebra
    14种机器学习常见算法分类汇总
    高速充电技术介绍
    javacc学习总结
    组合查询(机房重构知识点总结)
    Linux下vi编辑器的使用
  • 原文地址:https://www.cnblogs.com/tdmins/p/9845632.html
Copyright © 2011-2022 走看看