當前位置: 首頁>>代碼示例>>C#>>正文


C# StringContent.ReadAsStringAsync方法代碼示例

本文整理匯總了C#中System.Net.Http.StringContent.ReadAsStringAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# StringContent.ReadAsStringAsync方法的具體用法?C# StringContent.ReadAsStringAsync怎麽用?C# StringContent.ReadAsStringAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.Http.StringContent的用法示例。


在下文中一共展示了StringContent.ReadAsStringAsync方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

    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();
    }
開發者ID:NikolayKostadinov,項目名稱:Homeworks,代碼行數:12,代碼來源:Program.cs

示例2: ReadingStringContent

        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);
        }
開發者ID:sara62,項目名稱:WebApiKoans,代碼行數:17,代碼來源:AboutContent.cs

示例3: ReadAsStringAsync

 public void ReadAsStringAsync()
 {
     var sc = new StringContent ("abž");
     var res = sc.ReadAsStringAsync ().Result;
     Assert.AreEqual ("abž", res, "#1");
 }
開發者ID:RainsSoft,項目名稱:dotnet-httpclient35,代碼行數:6,代碼來源:StringContentTest.cs

示例4: ShouldBeAbleToCreateStringContent

        public void ShouldBeAbleToCreateStringContent()
        {
            //Arrange

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

            //Assert
            Assert.IsNotNull(content);
            Assert.AreEqual("Hello World",content.ReadAsStringAsync().Result);
        }
開發者ID:filipw,項目名稱:RestAgent,代碼行數:11,代碼來源:HttpContentTests.cs

示例5: RequestToken

		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;
		}
開發者ID:private-boolean,項目名稱:GestureSample,代碼行數:27,代碼來源:LoginPage.cs


注:本文中的System.Net.Http.StringContent.ReadAsStringAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。