有httponly的cookie,在httpwebreqeust请求时,会获取不到,可以采用直接获取head中的set-cookie,再转换成Cookie添加到CookieContainer中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<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方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。