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}