Пример #1
0
        protected async Task <string> GetHtmlAsync(string url)
        {
            try
            {
                string html = await HttpBaseService.SendGetRequest(url);

                //byte[] bytes = Encoding.UTF8.GetBytes(html);
                //html = Encoding.GetEncoding("GBK").GetString(bytes);
                return(html);
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        protected async Task <T> PostJsonAsync <T>(string uri, string body) where T : class
        {
            try
            {
                string json = await HttpBaseService.SendPostRequest(uri, body);

                if (json != null)
                {
                    return(JsonHelper.Deserlialize <T>(json));
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Post
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uri"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public async Task <JsonObject> PostJsonAsync <T> (string uri, T t) where T : class
        {
            string body = JsonHelper.Serializer(t);

            try
            {
                string json = await HttpBaseService.SendPostRequest(uri, body);

                if (json != null)
                {
                    return(JsonObject.Parse(json));
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #4
0
        public async Task <ReturnT> PostJsonAsync <SendT, ReturnT>(string uri, SendT sendT) where ReturnT : class
        {
            string body = JsonHelper.Serializer(sendT);

            try
            {
                string json = await HttpBaseService.SendPostRequest(uri, body);

                if (json != null)
                {
                    return(JsonHelper.Deserlialize <ReturnT>(json));
                }
                return(null);
            }
            catch (Exception e)
            {
                Debug.WriteLine("ApiBaseService PostJson" + e.Message);
                return(null);
            }
        }
Пример #5
0
        protected async Task <T> GetResponseAsync <T>(string url) where T : class
        {
            try
            {
                string json = await HttpBaseService.SendGetRequest(url);

                if (json != null)
                {
                    return(JsonHelper.Deserlialize <T>(json));
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #6
0
        protected async Task <WriteableBitmap> GetImageAsync(string url)
        {
            try
            {
                IBuffer buffer = await HttpBaseService.SendGetRequestAsBytes(url);

                if (buffer != null)
                {
                    BitmapImage bi = new BitmapImage();

                    using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                    {
                        Stream stream2Write = stream.AsStreamForWrite();
                        await stream2Write.WriteAsync(buffer.ToArray(), 0, (int)buffer.Length);

                        await stream2Write.FlushAsync();

                        stream.Seek(0);

                        await bi.SetSourceAsync(stream);

                        WriteableBitmap wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
                        stream.Seek(0);
                        await wb.SetSourceAsync(stream);

                        return(wb);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }