概述
string url = "https://www.baidu.com";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
string postdata = "phone=111111&password=2222222";
byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(postdata);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = requestBytes.Length;
req.Referer = "https://www.xxx.com";
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
string backstr = sr.ReadToEnd();
//Response.Write(backstr);
sr.Close();
res.Close();
string cookiestr = res.Headers.Get("Set-Cookie");//获取Cookie
//foreach (Cookie coo in res.Cookies)
// Response.Write(coo.Name + "==" + coo.Value + "<br/>");
string aaa = "";
foreach (Cookie coo in res.Cookies)
{
aaa += coo.Value + ",";
}
//显示"登录"
return backstr + "-----------------------------------------------------------------" + aaa;
最后
以上就是成就招牌为你收集整理的.net post 模拟登录提交 获取 cookie的全部内容,希望文章能够帮你解决.net post 模拟登录提交 获取 cookie所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复