问题描述
好吧,我可能很笨,因为我是唯一一个问这种问题的人,因为我没有看到类似的问题,但请原谅我:|。隔离只是让我试着学习更多的编程语言,无事可做。对不起,如果我每次都要求解决方案。因为我已经尝试过研究,但一无所获。
无论如何,所以我尝试从带有 System.Net.Http;
的购物网页中检索 Cookie,它应该在浏览器 cookie 中包含 csrftoken。我之前尝试过使用 Python,但没有检索到 cookie,但是由于某些原因,使用 C#,我检索到了一些。但是,我没有收到 csrftoken cookie。我认为这是因为 cookie 是基于浏览器会话的? :/。 I've seen this guy getting his csrftoken,but reading the code is a bit confusing for me. 如何检索 csrftoken 会话 cookie?。
无论如何,这是我目前正在使用的代码。
try
{
CookieContainer container = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://shopee.co.id/");
request.Proxy = null;
request.CookieContainer = container;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/70.0.3538.110 Safari/537.36";
request.Referer = "https://shopee.co.id";
request.Headers.Add("authority","shopee.co.id");
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
foreach (Cookie cookie in response.Cookies)
{
Console.WriteLine("Name =" + cookie.Name);
Console.WriteLine("Value =" + cookie.Value);
Console.WriteLine("Path =" + cookie.Path);
Console.WriteLine("Domain =" + cookie.Domain);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)