一网站,登录成功后,进入必须登录了才能访问的页面时要提交以下Cookie,
用Fiddle换取到的:
1
|
Cookie: ASP.NET_SessionId=4lfgopz3bft2hwbfr20tve55; timeStamp=1 |
现在我是这样设置Cookie的:
// 解析Cookie
/// </summary>
/// <param name="response"></param>
private
void
ParseCookie(HttpWebResponse response)
{
if
(!IgnoreCookies)
{
string
cookiesExpression = response.Headers[
"Set-Cookie"
];
if
(!
string
.IsNullOrEmpty(cookiesExpression))
{
Uri cookieUrl =
new
Uri(
string
.Format(
"{0}://{1}:{2}/"
,
response.ResponseUri.Scheme,
response.ResponseUri.Host,
response.ResponseUri.Port));
_cookieContainer.SetCookies(cookieUrl, cookiesExpression);
}
}
}
但是这样设置最终的Cookie是这个样子的:
Cookie: ASP.NET_SessionId=4lfgopz3bft2hwbfr20tve55;
导致访问网页提提示302:
HTTP/1.1 302 Found
Date: Mon, 14 Oct 2013 14:35:28 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Location:
Cache-Control: private
Content-Type: text/html; charset=GB18030
Content-Length: 117
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href=''>here</a>.</h2>
</body></html>
【疑难】怎样才能把字符串:timeStamp=1,追加到最后呢?
参考:
Cookie.TimeStamp 属性 (System.Net)
http://msdn.microsoft.com/zh-cn/library/system.net.cookie.timestamp(VS.90).aspx