我正在发送请求,但 cookie 没有存储在我的容器中以进行响应?
代码示例 -
string uri = "https://www.localhost.com/"
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.ContentType = "application/x-www-form-urlencoded";
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
using (Stream stream = request.GetRequestStream())
{
byte[] bytes = new UTF8Encoding().GetBytes(s);
stream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream2 = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream2, Encoding.UTF8))
{
str6 = reader.ReadToEnd();
}
}
}
如您所见,我已经实施
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
哪个应该将来自请求的 cookie 存储在容器中,以便在响应权中进一步使用?就像响应需要请求 cookie 来加载页面一样。