Exemplo n.º 1
0
        public async void HttpBinPostForStream()
        {
            var url        = new Uri("http://httpbin.org/post");
            var parameters = new Dictionary <string, string> {
                { "foo", "bar" }
            };

            using (var defaultHttpService = new DefaultHttpService(Logger))
                using (var stream = await defaultHttpService.PostForStreamAsync(url, parameters))
                    using (var streamReader = new StreamReader(stream))
                        using (var jsonTextReader = new JsonTextReader(streamReader))
                        {
                            var serializer = new JsonSerializer();
                            var response   = serializer.Deserialize <JToken>(jsonTextReader);
                            Logger.Log(response.ToString(Formatting.Indented));
                            response["form"]["foo"].ToString().Should().Be("bar");
                            response["url"].ToString().Should().Contain(url.AbsoluteUri);
                        }
        }
Exemplo n.º 2
0
        public async void VkApiPostForStream()
        {
            var url        = new Uri("https://api.vk.com/method/users.get");
            var parameters = new Dictionary <string, string> {
                { "user_ids", "1" }
            };

            using (var defaultHttpService = new DefaultHttpService(Logger))
                using (var stream = await defaultHttpService.PostForStreamAsync(url, parameters))
                    using (var streamReader = new StreamReader(stream))
                        using (var jsonTextReader = new JsonTextReader(streamReader))
                        {
                            var serializer = new JsonSerializer();
                            var response   = serializer.Deserialize <JToken>(jsonTextReader);
                            var content    = response["response"][0];
                            content["first_name"].ToString().Should().Be("Павел");
                            content["last_name"].ToString().Should().Be("Дуров");
                        }
        }