コード例 #1
0
        async static void myGetRequest(string url, TextBox theHeaderBox, TextBox theTextBox)
        {
            using (HttpClient myClient = new HttpClient())
            {
                using (HttpResponseMessage myResponse = await myClient.GetAsync(url))
                {
                    using (HttpContent myContent = myResponse.Content)
                    {
                        theTextBox.Text = await myContent.ReadAsStringAsync();

                        HttpContentHeaders myHeader = myContent.Headers;
                        theHeaderBox.Text = myHeader.ToString();
                    }
                }
            }
        }
コード例 #2
0
        public void CopyTo_CopiesContentHeaders()
        {
            // Arrange
            HttpContentHeaders source = FormattingUtilities.CreateEmptyContentHeaders();

            source.ContentType     = MediaTypeHeaderValue.Parse("application/json; charset=utf8; parameter=value");
            source.ContentLength   = 1234;
            source.ContentLocation = new Uri("http://some.host");
            source.Add("test-name1", "test-value1");
            source.Add("test-name2", "test-value2");

            HttpContentHeaders destination = FormattingUtilities.CreateEmptyContentHeaders();

            // Act
            source.CopyTo(destination);

            // Assert
            Assert.Equal(source.ToString(), destination.ToString());
        }
コード例 #3
0
        async static void myPostRequest(string url, TextBox theHeaderBox, TextBox theTextBox)
        {
            // use http://ptsv2.com/
            IEnumerable <KeyValuePair <string, string> > myQueries = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("theQuery1", "theArgument1"),
                new KeyValuePair <string, string>("theQuery2", "theArgument2"),
            };
            HttpContent myQuery = new FormUrlEncodedContent(myQueries);

            using (HttpClient myClient = new HttpClient())
            {
                using (HttpResponseMessage myResponse = await myClient.PostAsync(url, myQuery))
                {
                    using (HttpContent myContent = myResponse.Content)
                    {
                        theTextBox.Text = await myContent.ReadAsStringAsync();

                        HttpContentHeaders myHeader = myContent.Headers;
                        theHeaderBox.Text = myHeader.ToString();
                    }
                }
            }
        }