应用c#读取带cookie的http数据
@(编程)
private static string Login()
{
string url = string.Format("{0}/login-submit.html?identity=teacher&loginName={1}&password={2}", Config.HOST, Config.USER, Config.PASSWORD);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
return response.Headers.Get("Set-Cookie");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return errorMsg;
}
}
private static string GetMethod(string cookie)
{
string url = string.Format("{0}/teacher/student/employment-list.html", Config.HOST);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
CookieContainer co = new CookieContainer();
co.SetCookies(new Uri(url), cookie);
request.CookieContainer = co;
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return errorMsg;
}
}