一聚教程网:一个值得你收藏的教程网站

热门教程

httpwebreqeust读取httponly的cookie方法

时间:2022-06-25 14:33:10 编辑:袖梨 来源:一聚教程网

有httponly的cookie,在httpwebreqeust请求时,会获取不到,可以采用直接获取head中的set-cookie,再转换成Cookie添加到CookieContainer中

 代码如下 复制代码

stringcookieStr = resp.Headers["Set-Cookie"];

string[] cookstr = cookieStr.Split(';');

        foreach(stringstrincookstr)

        {

            string[] arr = str.Trim().Split(',');

            foreach(stringstr1inarr)

            {

              if(str1.IndexOf("=") != -1)

              {

                string[] cookieNameValue = str1.Trim().Split('=');

                if(cookieNameValue[0] !="Expires"&& cookieNameValue[0] !="Domain"

                  && cookieNameValue[0] !="Path")

                {

                  Cookie ck =newCookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString());

                  ck.Domain =".163.com";

                  cc.Add(ck);

                }

              }

            }

        }

热门栏目