Esempio n. 1
0
        async Task <Responce> RetriveByteArrayFromUrlAsync(string url, HttpMethod method, ParametersCollection parametersCollection = null)
        {
            var request = new WebReqvestBuilder(url, method)
                          .AddParameters(parametersCollection)
                          .CreateWebReqvest();

            var res = new Responce();

            request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            using (var response = (HttpWebResponse)await request.GetResponseAsync())
            {
                res.StatusCode = response.StatusCode;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    res.Headers = GetHeaders(response.Headers);
                    using (var ms = new MemoryStream())
                    {
                        using (var stream = response.GetResponseStream())
                        {
                            stream.CopyTo(ms);
                        }
                        res.Data = ms.ToArray();
                    }
                }
            }
            return(res);
        }
Esempio n. 2
0
        async Task <T> RetriveDataFromUrlAsync <T>(string url, HttpMethod method, ParametersCollection parametersCollection = null)
        {
            var request = new WebReqvestBuilder(url, method)
                          .AddParameters(parametersCollection)
                          .CreateWebReqvest();

            using (var response = (HttpWebResponse)await request.GetResponseAsync())
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        string responseText = await reader.ReadToEndAsync();

                        var res = JsonConvert.DeserializeObject <T>(responseText);
                        return(res);
                    }
                }
                else
                {
                    return(default);