Beispiel #1
0
    static void Main(string[] args) {
        var httpContent = new StringContent(@"
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
");
        Console.WriteLine(httpContent.ReadAsStringAsync().Result);
        Console.WriteLine("Initial size: {0} bytes", httpContent.Headers.ContentLength);

        var compressedContent = new CompressedContent(httpContent, "gzip");
        var result = compressedContent.ReadAsStringAsync().Result;
        Console.WriteLine("Compressed size: {0} bytes", compressedContent.Headers.ContentLength);
        Console.ReadLine();
    }
Beispiel #2
0
        public static void ReadingStringContent()
        {
            // Arguably the simplest of the `HttpContent` types is `StringContent`.
            // You create a new `StringContent` in the normal way you create .NET instances.
            // Note that in F# you need to use the `new` keyword because HttpContent
            // implements `IDisposable`.
            var content = new StringContent("Hello, string!");

            // `HttpContent` contains many methods and extension methods for reading its data.
            // All the read methods are asynchronous, as they are generally intended to read
            // data from a network stream. Here we will read the string content back out
            // using `ReadAsStringAsync`.
            var body = content.ReadAsStringAsync().Result;
            
            // Verify that the data we read was the same as we submitted to the `StringContent`.
            Helpers.AssertEquality(Helpers.__, body);
        }
 public void ReadAsStringAsync()
 {
     var sc = new StringContent ("abž");
     var res = sc.ReadAsStringAsync ().Result;
     Assert.AreEqual ("abž", res, "#1");
 }
Beispiel #4
0
 static void Main(string[] args) {
     var stringContent = new StringContent("Hello World");
     Console.WriteLine(stringContent.ReadAsStringAsync().Result);
     Console.ReadLine();
 }
Beispiel #5
0
        public void ShouldBeAbleToCreateStringContent()
        {
            //Arrange

            //Act
            var content = new StringContent("Hello World");

            //Assert
            Assert.IsNotNull(content);
            Assert.AreEqual("Hello World",content.ReadAsStringAsync().Result);
        }
		private async Task<GoogleOauthResponse> RequestToken(string authorizationString)
		{
			Debug.WriteLine("CODE REQUEST:" + authorizationString);

			HttpClient mClient = new HttpClient();
			mClient.BaseAddress =  new Uri("https://www.googleapis.com/");
			mClient.DefaultRequestHeaders.Accept.Clear();
			mClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


			StringBuilder tokenRequestStringBuilder = new StringBuilder();
			tokenRequestStringBuilder.Append("code=" + authorizationString + "&");
			tokenRequestStringBuilder.Append("client_id=" + APP_ID + "&");
			tokenRequestStringBuilder.Append("client_secret=" + CLIENT_SECRET + "&");
			tokenRequestStringBuilder.Append("redirect_uri=http://localhost:" + LISTEN_PORT + "&");
			tokenRequestStringBuilder.Append("grant_type=authorization_code");

			StringContent mHttpContent = new StringContent(tokenRequestStringBuilder.ToString());
			mHttpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
			string httpContentString = await mHttpContent.ReadAsStringAsync();
			Debug.WriteLine("HTTP REQUEST:-------------------\n" + httpContentString);
			HttpResponseMessage response = await mClient.PostAsync("oauth2/v4/token", mHttpContent);
			//Debug.WriteLine("TOKEN REQUEST RESPONSE: _-----------------\n" + response.Content);
			string responseJsonString = await response.Content.ReadAsStringAsync();
			GoogleOauthResponse responseDataStruct = JsonConvert.DeserializeObject<GoogleOauthResponse>(responseJsonString);
			return responseDataStruct;
		}