How to change the encoding of the HttpClient response

前端 未结 3 1538
我在风中等你
我在风中等你 2020-12-17 17:38

I\'m trying to learn about Async programming using VS2012 and its Async Await keyword. That is why i wrote this piece of code:



        
3条回答
  •  青春惊慌失措
    2020-12-17 18:18

    WinRT 8.1 C#

    using Windows.Storage.Streams;
    using System.Text;
    using Windows.Web.Http;
    
    // in some async function
    
    Uri uri = new Uri("http://something" + query);
    HttpClient httpClient = new HttpClient();
    
    IBuffer buffer = await httpClient.GetBufferAsync(uri);
    string response = Encoding.UTF8.GetString(buffer.ToArray(), 0, (int)(buffer.Length- 1));
    
    // parse here
    
    httpClient.Dispose();
    

提交回复
热议问题