111,125
社区成员
发帖
与我相关
我的任务
分享 cookieHeader = response.Headers["Set-cookie"]; //get the cookie
webRequest.Headers.Add("Cookie", cookieHeader);
//////////////////////////////////////////////////////////////////////////
//photo page method 1-3 down load file
string file_name = "";
url = GetDownloadUrl(responseData);
url_reference = GetDownloadUrlRe(url,responseData);
file_name = GetFileNameViaURL(url);
//DownloadFile(url, "f:\\" + file_name, "a");
webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.MediaType = "GET";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.1) Gecko/20100101 Firefox/6.0.1";
webRequest.Host = "download.shutterstock.com";
webRequest.UseDefaultCredentials = true;
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest.KeepAlive = true;
webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
webRequest.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
webRequest.Headers.Add("Cookie", cookieHeader);//session in cookie
webRequest.Headers.Add("Pragma", "no-cache");
response = (HttpWebResponse)webRequest.GetResponse();//will the 403 error
CookieContainer cookies = new CookieContainer();
//////////////////////////////////////////////////////////////////////////
// first, request the login form to get the viewstate value
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.Method = "GET";
webRequest.UserAgent = UserAgent;
webRequest.CookieContainer =cookies;
webRequest.Referer = "";
webRequest.Host = "www.shutterstock.com";
webRequest.Accept = "text/html, application/xhtml+xml, */*";
webRequest.KeepAlive = true;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader responseReader = new StreamReader(response.GetResponseStream());
cookieHeader = response.Headers["Set-cookie"]; //get the cookie
OutputCookieData(url, response);
private void OutputCookieData(String page_url,HttpWebResponse response)
{
StringBuilder sb = new StringBuilder();
sb.Append("Url:"+page_url+Environment.NewLine);
int i = 0;
foreach (Cookie cook in response.Cookies)
{
i = i + 1;
sb.Append(i+". Cookie:");
sb.Append(String.Format("{0} = {1}", cook.Name, cook.Value));
sb.Append(String.Format(" Domain: {0}", cook.Domain));
sb.Append(String.Format(" Path: {0}", cook.Path));
sb.Append(String.Format(" Port: {0}", cook.Port));
sb.Append(String.Format(" Secure: {0}", cook.Secure));
sb.Append(String.Format(" When issued: {0}", cook.TimeStamp));
sb.Append(String.Format(" Expires: {0} (expired? {1})",
cook.Expires, cook.Expired));
sb.Append(String.Format(" Don't save: {0}", cook.Discard));
sb.Append(String.Format(" Comment: {0}", cook.Comment));
sb.Append(String.Format(" Uri for comments: {0}", cook.CommentUri));
sb.Append(String.Format(" Version: RFC {0}", cook.Version == 1 ? "2109" : "2965"));
// Show the string representation of the cookie.
sb.Append(String.Format("String: {0}", cook.ToString()));
sb.Append(Environment.NewLine);
}
sb.AppendLine(Environment.NewLine);
WriteCookieLog(sb.ToString());
}
获取的值里面根本就没有,为啥浏览器里面有,我缺在哪里
rl:https://secure.shutterstock.com/login.mhtml
Url:http://www.shutterstock.com/pic-120804181.html
1. Cookie:ssssidd = 7ea9c80b841b8f48fb78a43573e0b3c7 Domain: www.shutterstock.com Path: / Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 2013/7/19 15:39:16 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: ssssidd=7ea9c80b841b8f48fb78a43573e0b3c7
2. Cookie:visit_id = 2064191922 Domain: .shutterstock.com Path: / Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 2013/6/19 16:09:17 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: visit_id=2064191922
3. Cookie:sst = 212:815 Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: sst=212:815
4. Cookie:380:1343 = Domain: .shutterstock.com Path: / Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 2013/6/19 16:09:17 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 380:1343=
5. Cookie:psst = 73:196 Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: psst=73:196
6. Cookie:115:466 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 115:466=
7. Cookie:158:572 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 158:572=
8. Cookie:200:761 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 200:761=
9. Cookie:209:809 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 209:809=
10. Cookie:218:872 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 218:872=
11. Cookie:221:886 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 221:886=
12. Cookie:230:958 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 230:958=
13. Cookie:332:1160 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 332:1160=
14. Cookie:377:1328 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 377:1328=
15. Cookie:389:1379 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 389:1379=
16. Cookie:430:1486 = Domain: www.shutterstock.com Path: /pic-120804181.html Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 0001/1/1 0:00:00 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 430:1486=
17. Cookie:433:1498 = Domain: .shutterstock.com Path: / Port: Secure: False When issued: 2013/6/19 15:39:18 Expires: 2013/9/17 15:39:17 (expired? False) Don't save: False Comment: Uri for comments: Version: RFC 2965String: 433:1498=