Exemple #1
0
        public string LoginString(string url)
        {
            FileLog.Log($"LoginString Requset {url}");
            var newurl = url + "&fun=new&version=v2";
            var client = new AsyncHttpClient().UserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
                         .Header("Accept-Encoding", "gzip,deflate,br")
                         .Header("Accept-Language", "zh-CN,zh;q=0.9")
                         .Header("Accept", "application/json, text/plain, */*")
                         .Header("Connection", "keep-alive")
                         .Header("Host", "wx2.qq.com").Cookies(cookieContainer)
                         .AutomaticDecompression(DecompressionMethods.Deflate | DecompressionMethods.GZip)
                         .Referer("https://wx2.qq.com/").Url(newurl);
            var response = client.Get().Result;
            var str      = response.GetString();

            FileLog.Log($"GetString Response {str}");
            return(str);
        }
Exemple #2
0
            public async Task <IBuffer> download(string url, object extra)
            {
                AsyncHttpClient http = new AsyncHttpClient();

                http.Url(url);
                if (extra != null)
                {
                    //把相关信息传过去作防盗验证
                    var user = extra as User;
                    http.Header("UserID", user.UserID);
                    http.Header("Sex", user.Sex);
                    http.Header("APPID", "1111");
                    http.Header("APPMK", "XXXXXXXXXXXXXXXX");
                }

                var rsp = await http.Get();

                return(rsp.getBuffer());
            }
Exemple #3
0
        private static async void doHttp(SdSource source, HttpMessage msg, __CacheBlock cache, HttpCallback callback)
        {
            var encoding = Encoding.GetEncoding(msg.config.encode());

            AsyncHttpClient client = new AsyncHttpClient();

            client.UserAgent(msg.config.ua());
            client.Encoding(msg.config.encode());

            foreach (String key in msg.header.Keys)
            {
                client.Header(key, msg.header[key]);
            }

            string newUrl = null;

            if (msg.url.IndexOf(" ") >= 0)
            {
                newUrl = Uri.EscapeUriString(msg.url);
            }
            else
            {
                newUrl = msg.url;
            }

            client.Url(newUrl);

            string temp = null;

            AsyncHttpResponse rsp = null;

            try {
                if ("post".Equals(msg.config.method))
                {
                    rsp = await client.Post(msg.form);
                }
                else
                {
                    rsp = await client.Get();
                }

                if (rsp.StatusCode == HttpStatusCode.OK)
                {
                    source.setCookies(rsp.Cookies);
                    temp = rsp.GetString();

                    if (string.IsNullOrEmpty(rsp.location) == false)
                    {
                        Uri uri = new  Uri(msg.url);
                        rsp.location = uri.Scheme + "://" + uri.Host + rsp.location;
                    }
                }
            }
            catch (Exception ex) {
                Util.log(source, "HTTP", ex.Message);
            }

            if (temp == null)
            {
                if (cache == null || cache.value == null)
                {
                    callback(-2, msg, null, rsp.location);
                }
                else
                {
                    callback(1, msg, cache.value, rsp.location);
                }
            }
            else
            {
                callback(1, msg, temp, rsp.location);
            }
        }