public void UpdateCookies(List<string> tmpCookies) { var newCookies = new List<string>(); if (tmpCookies != null) { newCookies.AddRange(tmpCookies); } if (newCookies.Count > 0) { foreach (var it in newCookies) { var cookie = new QQHttpCookie(it); var oldCookie = this.GetCookie(cookie.Name, null); //如果有之前相同名字的Cookie,删除之前的cookie if (oldCookie != null) { CookieContainer.Remove(oldCookie); //如果新cookie的值不为空,就添加到新的cookie到列表中 if (!string.IsNullOrEmpty(cookie.Value)) { CookieContainer.Add(cookie); } } else { CookieContainer.Add(cookie); } } } }
public QQHttpCookie GetCookie(string name, string url) { QQHttpCookie qqHttpCookie = null; var cookie = _cc.GetCookies(new Uri(url))[name]; if (cookie != null) { qqHttpCookie = new QQHttpCookie(cookie); } // else Context.Logger.LogError($"获取cookie失败:{name}"); return(qqHttpCookie); }
public QQHttpCookie GetCookie(string name, string url) { var list = _cookieContainer.GetAllCookies().ToList(); QQHttpCookie qqHttpCookie = null; Cookie cookie = _cookieContainer.GetCookies(new Uri(url))[name] ?? _cookieContainer.GetCookies(name).FirstOrDefault(); if (cookie != null) { qqHttpCookie = new QQHttpCookie(cookie); } else { MyLogger.Default.Error($"获取cookie失败:{name}"); } return(qqHttpCookie); }
public override QQHttpRequest OnBuildRequest() { IHttpService httpService = Context.GetSerivce<IHttpService>(QQServiceType.HTTP); QQHttpCookie ptwebqq = httpService.GetCookie("ptwebqq", QQConstants.URL_GET_USER_CATEGORIES); QQSession session = Context.Session; QQAccount account = Context.Account; JObject json = new JObject(); json.Add("vfwebqq", session.Vfwebqq); json.Add("hash", QQEncryptor.GetHash(account.Uin + "", ptwebqq.Value)); QQHttpRequest req = CreateHttpRequest("POST", QQConstants.URL_GET_GROUP_NAME_LIST); req.AddPostValue("r", JsonConvert.SerializeObject(json)); req.AddHeader("Referer", QQConstants.REFFER); return req; }
public QQHttpCookie GetCookie(string name, string url) { var list = _cookieContainer.GetAllCookies().ToList(); QQHttpCookie qqHttpCookie = null; Cookie cookie = _cookieContainer.GetCookies(new Uri(url))[name] ?? _cookieContainer.GetCookies(name).FirstOrDefault(); if (cookie != null) qqHttpCookie = new QQHttpCookie(cookie); else MyLogger.Default.Error($"获取cookie失败:{name}"); return qqHttpCookie; }