public class WebClientEx : WebClient
{
private CookieContainer cookie = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookie;
}
return request;
}
}
NameValueCollection postValues = new NameValueCollection();
postValues.Add("Email", info.username);
postValues.Add("Pwd", info.userpwd);
WebClientEx client = new WebClientEx();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
Encoding enc = Encoding.GetEncoding("UTF-8");
client.UploadValues(login, "POST", postValues);
client.DownloadFile(file, path);