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

    }

  • 相关阅读:
    页面显示This is the initial start page for the WebDriver server.的解决办法
    Robot Framework + Selenium library + IEDriver环境搭建
    selenium之 chromedriver与chrome版本映射表(更新至v2.38)
    Python 各种测试框架简介(三):nose
    Python 各种测试框架简介
    python 几种常用测试框架
    一步一步教你搭建和使用FitNesse
    xss 学习记录
    android root 原理
    rtd1296 mtd 设备驱动分析
  • 原文地址:https://www.cnblogs.com/tdmins/p/9845632.html
Copyright © 2011-2022 走看看