rotocolType.Tcp);
25 s.Connect(EPhost);
26 if (!s.Connected)
27 {
28 strHTML = "链接主机失败";
29 }
30 s.Send(ByteGet, ByteGet.Length, SocketFlags.None);
31 strHTML = Recv(s, Encoding.GetEncoding(encoding));
32 return strHTML;
33 }
处理cookies以及重定向问题
///
/// 从返回的源代码中提取cookies 以及301或302跳转
///
///
///
///
public string GetCookies(string html, out string location)
{
StringBuilder sbCookies = new StringBuilder();
location = string.Empty;
string[] arr = html.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string str in arr)
{
if (str.StartsWith("Set-Cookie: "))
{
int intStart = str.IndexOf(";");
string strCookie = str.Substring(12, intStart - 11);
sbCookies.Append(strCookie);
}
if (str.StartsWith("Location:"))
{
location = str.Substring(10);
}
}
return sbCookies.ToString();
}