I use my account to login www.shutterstock.com in IE or Firefox is fine,but use HttpWebRequest cann't,I have save cookie data in CookieContainer(),My Programe Get cookie is different number with IE Browser,why not,I have assign the request info UserAgent,Referer,Host ...
Anyone can tell me what's problem.How Can i do can login this web.following is my code. account is virtual,not true.
string session_id = "";
string str_key = "";
string str_value = "";
string url = "";
url = "http://www.shutterstock.com/";
CookieContainer cookies = new CookieContainer();
//////////////////////////////////////////////////////////////////////////
// first, request the login form to get the viewstate value
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
webRequest.MediaType = "GET";
webRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
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());
OutputCookieData(url, response);
foreach (Cookie cookie_object in response.Cookies)
{
str_key = HttpUtility.UrlDecode(cookie_object.Name);
str_value = HttpUtility.UrlDecode(cookie_object.Value);
if (str_key == "ssssidd")
{
session_id = str_value;
break;
}
//str_cookie += str_key + "=" + str_value + Environment.NewLine;
}
string responseData = responseReader.ReadToEnd();
responseReader.Close();
WriteDayLog(responseData);
// extract the viewstate value and build out POST data
string postData =
String.Format(
"user=susimage&pass=110205&session_id={0}",
session_id
);
//////////////////////////////////////////////////////////////////////////
// have a cookie container ready to receive the forms auth cookie
// now post to the login form
webRequest = WebRequest.Create("https://secure.shutterstock.com/login.mhtml") as HttpWebRequest;
webRequest.Method = "POST";
webRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cookies;
webRequest.KeepAlive = true;
webRequest.Referer = "http://www.shutterstock.com/";
webRequest.Host = "secure.shutterstock.com";
// write the form values into the request message
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postData);
requestWriter.Close();
// we don't need the contents of the response, just the cookie it issues
response = (HttpWebResponse)webRequest.GetResponse();
responseReader = new StreamReader(response.GetResponseStream());
OutputCookieData("https://secure.shutterstock.com/login.mhtml", response);
responseData = responseReader.ReadToEnd();
responseReader.Close();
WriteDayLog(responseData);