软件编程
位置:首页>> 软件编程>> C#编程>> httpwebreqeust读取httponly的cookie方法

httpwebreqeust读取httponly的cookie方法

作者:jingxian  发布时间:2022-04-19 19:47:05 

标签: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>
0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com