久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Windows 應用商店應用程序中使用 httpclient 獲取

Getting an UTF-8 response with httpclient in Windows Store apps(在 Windows 應用商店應用程序中使用 httpclient 獲取 UTF-8 響應)
本文介紹了在 Windows 應用商店應用程序中使用 httpclient 獲取 UTF-8 響應的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在構建一個 Windows 應用商店應用,但我一直無法從 API 獲得 UTF-8 響應.

I'm building a Windows Store app, but I'm stuck at getting a UTF-8 response from an API.

這是代碼:

using (HttpClient client = new HttpClient())
{
    Uri url = new Uri(BaseUrl + "/me/lists");

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
    request.Headers.Add("Accept", "application/json");
    HttpResponseMessage response = await client.SendRequestAsync(request);
    response.EnsureSuccessStatusCode();

    string responseString = await response.Content.ReadAsStringAsync();

    response.Dispose();
}

reponseString 總是包含奇怪的字符,應該是像 é 這樣的重音符號,我嘗試使用流,但我在一些示例中找到的 API 不存在于Windows RT.

The reponseString always contains strange characters which should be accents like é, and I tried using a stream, but the API I found in some examples don't exist in Windows RT.

改進的代碼,仍然是同樣的問題.

improved code, still same problem.

推薦答案

你可以使用 response.Content.ReadAsBufferAsync() 而不是直接使用 response.Content.ReadAsStringAsync()@Kiewic 指向的代碼> 如下:

Instead of using response.Content.ReadAsStringAsync() directly you could use response.Content.ReadAsBufferAsync() pointed by @Kiewic as follows:

var buffer = await response.Content.ReadAsBufferAsync();
var byteArray = buffer.ToArray();
var responseString = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);

這在我的情況下有效,我想使用 UTF8 應該可以解決大部分問題.現在想想為什么沒有辦法使用 ReadAsStringAsync 來做到這一點:)

This is working in my case and I guess that using UTF8 should solve most of the issues. Now go figure why there is no way to do this using ReadAsStringAsync :)

這篇關于在 Windows 應用商店應用程序中使用 httpclient 獲取 UTF-8 響應的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點的“活動用戶數)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Best way to keep track of current online users(跟蹤當前在線用戶的最佳方式)
主站蜘蛛池模板: 九色在线| 日本精品裸体写真集在线观看 | 国产精品久久久久久久久久久久久 | 亚洲五码在线 | 国产网站在线播放 | 亚洲电影一级片 | 亚洲成人播放器 | 在线免费观看a级片 | 日日夜夜天天 | 亚洲一区二区三区欧美 | 国产午夜久久 | 国产综合第一页 | 国产精品中文 | 亚洲精品在线免费观看视频 | 天天躁日日躁狠狠很躁 | 成人午夜毛片 | 国产成人黄色 | 欧美a视频| 国产一区二区三区免费 | 伊人精品在线视频 | 国产一区 在线视频 | 午夜精品一区二区三区在线观看 | 在线视频a| 国产日韩一区二区 | 男女羞羞视频免费 | 国产精品美女一区二区 | 国产精品波多野结衣 | 午夜羞羞 | 综合久久综合久久 | 99热精品在线观看 | 视频三区 | 亚洲一区二区三区四区av | 亚洲国产免费 | 在线观看国产wwwa级羞羞视频 | 亚洲网站在线观看 | 综合二区| 亚洲乱码一区二区三区在线观看 | 一级片在线观看 | 免费看大片bbbb欧美 | 国产一级在线观看 | 日本亚洲一区二区 |