zoukankan      html  css  js  c++  java
  • ASP.NET数据传递:获取META信息

    ASP.NET中数据传递:获取用Meta传递的数据:
     1public static string GetMeta(string strFullUrl, string MateName)
     2{
     3//strFullUrl需要有Http前缀
     4HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strFullUrl);
     5myRequest.KeepAlive = false;
     6myRequest.Timeout = 30000;
     7myRequest.ReadWriteTimeout = 30000;
     8string content = "";
     9string strError = "";
    10try
    11{
    12HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    13StreamReader myReader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
    14//返回内容存放于content中
    15content = myReader.ReadToEnd();
    16myReader.Close();
    17myResponse.Close();
    18}

    19catch (Exception ex)
    20{
    21strError = ex.Message.ToString();
    22}

    23
    24//分析返回信息中的<meta>标志中content=的内容
    25RegexOptions RxOptions = RegexOptions.IgnoreCase;
    26string StrToGetMate =
    27@"<meta Name=\""{0}\"" content[\s]?=[\s\""\']+(.*?)[\""\']+.*?>";
    28Regex myRx = new Regex(string.Format(StrToGetMate, MateName), RxOptions);
    29Match myMt = myRx.Match(content);
    30if (null != myMt)
    31{
    32//有匹配内容
    33content = myMt.Groups[1].ToString();
    34}

    35//返回内容
    36if (strError.Length > 0)
    37{
    38return strError;
    39}

    40else
    41{
    42return content;
    43}

    44}

  • 相关阅读:
    LinkedList的使用方法
    规范HTML页面
    HTML总结(一)
    HTML标签学习总结
    java---线程池的使用
    java对excel表格的操作
    java对cookie及Session的操作
    硬盘分区工具gparted使用
    镜像, 转置, 锐化, 灰度,旋转
    ffmpeg解码
  • 原文地址:https://www.cnblogs.com/lixx/p/1190026.html
Copyright © 2011-2022 走看看