我想知道是否可以将 cookie 从一个 Web 客户端复制到另一个客户端。
原因
我正在使用并行 Web 请求,它会在每个新线程上创建新的 Web 客户端实例。
问题
信息是敏感的,需要使用 post 请求授权并保存 cookie。所以基本上那些新的 Web 客户端实例无法访问。我不想授权正在创建的每一个 Web 客户端,所以我想知道是否有可能以某种方式将 cookie 从一个 Web 客户端复制到另一个 Web 客户端。
示例代码
public class Scrapper
{
    CookieAwareWebClient _web = new CookieAwareWebClient();
    public Scrapper(string username, string password)
    {
        this.Authorize(username, password); // This sends correct post request and then it sets the cookie on _web
    }
    public string DowloadSomeData(int pages)
    {
        string someInformation = string.Empty;
        Parallel.For(0, pages, i =>
        {
            // Cookie is set on "_web", need to copy it to "web"
            var web = new CookieAwareWebClient(); // No authorization cookie here
            html = web.DownloadString("http://example.com/"); // Can't access this page without cookie
            someInformation += this.GetSomeInformation(html)
        });
        return someInformation;
    }
}
// This is cookie aware web client that I use
class CookieAwareWebClient : 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;
    }
}