小编Bar*_*dee的帖子

Xamarin Forms HttpClient PostAsync 总是抛出 NSMallocException

我们正在使用 Xamarin Forms 5 和 Visual Studio 2022 构建适用于 iOS 和 Android 的移动应用程序。当我们向任何 api 发出 Post 请求时,我们自己的外部 api 总是会返回:

Xamarin.PreBuilt.iOS[3728:2199180] Xamarin.iOS: Received unhandled ObjectiveC exception: NSMallocException Failed to grow buffer

GET 请求工作正常。我搜索了 Google 和 StackOverflow 但找不到任何帮助。我尝试增加 HttpClient.MaxResponseContentBufferSize 没有任何区别。

现在的应用程序非常简单,一个页面有一个测试按钮。后台代码如下:

public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private async void Button_Clicked(object sender, EventArgs e)
        {
            var client = new HttpClient();
            client.BaseAddress = new Uri("https://ptsv2.com/");

            string jsonData = @"{}";

            var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
            HttpResponseMessage …
Run Code Online (Sandbox Code Playgroud)

httpclient ios xamarin.forms

5
推荐指数
1
解决办法
771
查看次数

标签 统计

httpclient ×1

ios ×1

xamarin.forms ×1