httpwebreqeust讀取httponly的cookie辦法。本站提示廣大學習愛好者:(httpwebreqeust讀取httponly的cookie辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是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辦法就是分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持。