簡體   English   中英

Xamarin.Forms - HttpClient GetAsync 或 PostAsync 有時需要太長時間

[英]Xamarin.Forms - HttpClient GetAsync or PostAsync sometimes takes too long

I am using Xamarin.Forms and I am using HttpClient GetAsync and PostAsync to make calls to an api, my problem is the client is complaining that the application is too slow when it makes an api call. 無論如何我可以加快這個過程,還是有另一種更快的方法來調用 api? 這是一個示例方法:

public async Task<List<SubCatClass>> GetSubCategories(int category)
        {
            var client = new HttpClient();

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("category", category.ToString())
            });

            var response = await client.PostAsync(string.Format("https://exmample.com/api/index.php?action=getSubCategories"), content);

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

            List<SubCatClass> items = JsonConvert.DeserializeObject<List<SubCatClass>>(responseString);

            return items;

        }

這就是我所說的。

await webService.GetSubCategories(item.categoryid);

api 我可以完全控制代碼 (PHP) 和服務器。

任何幫助將非常感激。

提前致謝。

更新

我在 postman 中調用了 api,這是結果

在此處輸入圖像描述

您可以嘗試使用ModernHttpClient ,它會比默認使用 Xamarin 提高您的速度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM