当前位置: 首页>>代码示例>>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;未经允许,请勿转载。