久久久久久久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模板網!

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

相關文檔推薦

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?(是否有執(zhí)行 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级片毛片 | 永久免费看mv网站入口亚洲 | 国精产品一区二区 | 欧美性猛交xxxx黑人交 | 色激情网 | 黄色成人毛片 | 黄色三级小说 | 国产成人综合视频 | 欧美一区二区三区免费 | 亚洲一级二级三级 | 国产99对白在线播放 | www.亚洲精品| 日韩免费看 | 日韩视频免费在线观看 | 黄网站免费观看 | 综合久久99| 国产成人精品久久久 | 国产91av视频 | 国产精品久久网 | 懂色av一区二区夜夜嗨 | 欧美又大粗又爽又黄大片视频 | 国产精品自拍小视频 | 白浆在线 | 高清免费av | 少妇高潮久久久久久潘金莲 | 久久久久久九九九九 | 美日韩在线视频 | 日韩在线观看一区 | 久久久精品在线观看 | 欧美久久视频 | 亚洲视频网址 | 亚洲免费二区 | 成人自拍视频在线观看 | 伊人春色在线 | 色综合88| 香蕉视频色 | 国产一区一区 | 九色网址| 日韩视频免费 | 国产高清在线视频 | 久久福利网 |