There is this trend of cookies not turning up. I copy fiddler exactly and it should be a simple task since it's handled automatically anyway. Why am I not getting proper cookie retrieval?
public class HTTP : WebClient
{
public HTTP()
: this(new CookieContainer())
{ }
public HTTP(CookieContainer c)
{
CookieContainer = c;
}
public CookieContainer CookieContainer { get; set; }
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
var castRequest = request as HttpWebRequest;
if (castRequest != null)
{
castRequest.CookieContainer = CookieContainer;
castRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
castRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22";
}
return request;
}
}
public void checkUrl()
{
CookieContainer cookieJar = new CookieContainer();
HTTP client = new HTTP(cookieJar);
string responseData = client.DownloadString(url);
responseData = client.UploadString(url, loginData);
rtb.Text = responseData;
}