string link = @"http://localhost:2613/siteapi/getfile";
WebClient webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.Cookie, "accesscode=123456");
webClient.DownloadFileAsync(new Uri(link), @"c:\Download\" + "file.txt");
var cookieContainer = new CookieContainer();
_handler = new HttpClientHandler {CookieContainer = cookieContainer};
_client = new HttpClient(_handler);
private void SaveCookie()
{
var cookies = _handler.CookieContainer.GetCookies(new Uri(BaseUrl));
var cookie = cookies["PHPSESSID"];
using (var writer = new StreamWriter(_cookieFile))
{
writer.Write(cookie.ToJson());
}
}