示例#1
0
文件: Util.cs 项目: scaPEGoatno/SiteD
        private static async void doHttp(SdSource source, String url, Dictionary<String, String> args, SdNode config, __CacheBlock cache, HttpCallback callback) {


            var encoding = Encoding.GetEncoding(config.encode());

            AsyncHttpClient client = new AsyncHttpClient();

            if (config.isInCookie() && string.IsNullOrEmpty(source.cookies()) == false) {
                client.Cookies(source.cookies());
            }

            client.Header("User-Agent", source.ua());
            client.Encoding(config.encode());

            string newUrl = null;
            if (url.IndexOf(" ") >= 0)
                newUrl = Uri.EscapeUriString(url);
            else
                newUrl = url;

            if (config.isInReferer()) {
                client.Header("Referer", source.buildReferer(config, url));
            }

            if (string.IsNullOrEmpty(config.accept) == false) {
                client.Header("Accept", config.accept);
                client.Header("X-Requested-With", "XMLHttpRequest");
            }

            client.Url(newUrl);

            string temp = null;

            try {
                AsyncHttpResponse rsp = null;
                if ("post".Equals(config.method))
                    rsp = await client.Post(args);
                else
                    rsp = await client.Get();

                if (rsp.StatusCode == HttpStatusCode.Ok) {
                    source.setCookies(rsp.Cookies);
                    temp = rsp.GetString();
                }
            }
            catch(Exception ex) {
                Util.log(source, "HTTP", ex.Message);
            }

            if (temp == null) {
                if (cache == null)
                    callback(-2, null);
                else
                    callback(1, cache.value);
            }
            else
                callback(1, temp);
        }
示例#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();
            }
 private async void LoadData()
 {
     httpclient = new Noear.UWP.Http.AsyncHttpClient();
     httpclient.Url("http://tools.mobile.kugou.com/api/v1/welcome/list?plat=0&version=8150");
     var json = (await httpclient.Get()).GetString();
     var obj = Windows.Data.Json.JsonObject.Parse(json);
     voicedata = Class.data.DataContractJsonDeSerialize<ObservableCollection<VoiceData>>(obj.GetNamedObject("data").GetNamedArray("info").ToString());
     voicedata.Insert(0, new VoiceData() {name="经典版",id=0,source= "ms-appx:///Assets/welcome.mp3" });
     var nowid=(int)localSettings.Values["StartVoiceId"];
     foreach (var item in voicedata)
     {
         if (item.id == nowid)
         {
             item.isnow = "Visible";
             break;
         }
     }
     listview.ItemsSource = voicedata;
     listview.SelectionMode = ListViewSelectionMode.Single;
     listview.SelectionChanged += Listview_SelectionChanged;
 }
示例#4
0
文件: Util.cs 项目: noear/SiteD
        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);
        }