本文主要是介绍httpwebreqeust读取httponly的cookie,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
有httponly的cookie,在httpwebreqeust请求时,会获取不到,可以采用直接获取head中的set-cookie,再转换成Cookie添加到CookieContainer中
<pre name="code" class="csharp">string cookieStr = resp.Headers["Set-Cookie"];
string[] cookstr = cookieStr.Split(';');foreach (string str in cookstr){string[] arr = str.Trim().Split(',');foreach (string str1 in arr){if (str1.IndexOf("=") != -1){string[] cookieNameValue = str1.Trim().Split('=');if (cookieNameValue[0] != "Expires" && cookieNameValue[0] != "Domain"&& cookieNameValue[0] != "Path"){Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());ck.Domain = ".163.com";cc.Add(ck);}}}}
</pre><p></p><pre>
这篇关于httpwebreqeust读取httponly的cookie的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!