public static AsyncCookieContainer Create(CookieContainer cc) { AsyncCookieContainer acc = new AsyncCookieContainer(); List <Cookie> listCookies = new List <Cookie>(); Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, cc, new object[] { }); foreach (object pathList in table.Values) { SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember("m_list", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { }); foreach (CookieCollection colCookies in lstCookieCol.Values) { foreach (Cookie c in colCookies) { listCookies.Add(c); } } } foreach (Cookie cookie in listCookies) { acc.Add(new Cookie() { Name = cookie.Name, Value = cookie.Value, Domain = cookie.Domain, Path = cookie.Path }); } return(acc); }
protected async void Init(HttpResponseMessage rsp) { if (rsp.StatusCode == HttpStatusCode.OK) { this.Data = await rsp.Content.ReadAsByteArrayAsync(); } if (rsp.Headers != null) { foreach (var kv in rsp.Headers) { if ("Set-Cookie".Equals(kv.Key)) { if (Cookies == null) { Cookies = new AsyncCookieContainer(); } foreach (var cookieStr in kv.Value) { Cookies.Add(cookieStr); } } Headers[kv.Key] = string.Join(";", kv.Value); } } StatusCode = rsp.StatusCode; RequestMessage = rsp.RequestMessage; }
public AsyncHttpClient Cookies(AsyncCookieContainer cookies) { if (cookies != null) { _cookieContainerBuilder = CookieContainerBuilder.Create(cookies); } return(this); }
public static AsyncCookieContainer Create(string cookies) { AsyncCookieContainer acc = new AsyncCookieContainer(); string[] tempCookies = cookies.Split(';'); string tempCookie = null; int equalLength = 0;// =的位置 string cookieKey = null; string cookieValue = null; for (int i = 0; i < tempCookies.Length; i++) { if (!string.IsNullOrEmpty(tempCookies[i])) { tempCookie = tempCookies[i]; equalLength = tempCookie.IndexOf("="); if (equalLength != -1) //有可能cookie 无=,就直接一个cookiename;比如:a=3;ck;abc=; { cookieKey = tempCookie.Substring(0, equalLength).Trim(); if (equalLength == tempCookie.Length - 1) //这种是等号后面无值,如:abc=; { cookieValue = string.Empty; } else { cookieValue = tempCookie.Substring(equalLength + 1, tempCookie.Length - equalLength - 1).Trim(); } } else { cookieKey = tempCookie.Trim(); cookieValue = string.Empty; } acc.Add(new Cookie() { Name = cookieKey, Value = cookieValue }); } } return(acc); }
public static CookieContainerBuilder Create(AsyncCookieContainer cookies) { return(new CookieContainerBuilder(cookies)); }
public static CookieContainerBuilder Create(string cookies) { return(new CookieContainerBuilder(AsyncCookieContainer.Create(cookies))); }
private CookieContainerBuilder(AsyncCookieContainer asyncCookieContainer) { _asyncCookieContainer = asyncCookieContainer; }