ASP.NET資料傳遞:擷取META資訊

來源:互聯網
上載者:User
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}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.