【问题标题】:What is the best way to call my API in WASM?在 WASM 中调用我的 API 的最佳方式是什么?
【发布时间】:2020-06-23 04:14:04
【问题描述】:

我正在尝试连接到我的 API。 我正在使用 SwaggerClient 对其进行调用,但是当我这样做时,我得到 System.PlatformNotSupportedException: Property AutomaticDecompression is not supported。 那么调用我的 API 以使其在 WASM 上运行的最佳方式是什么?

【问题讨论】:

  • 我可以使用 var handler = new HttpClientHandler();没有 AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate 并访问 API,但之后整个应用程序冻结。

标签: webassembly uno-platform


【解决方案1】:

Uno 平台中 Web 服务的使用(假设为 http/json)与任何 .NET 应用程序的工作方式相同。使用HttpClient

我不熟悉 SwaggerClient,但我假设引擎盖下有一个 HttpClient。

对于 WebAssembly,您需要创建一个 WasmHttpHandler,然后将其作为 HttpClient 的 innerHandler 传入。

#if __WASM__
            var innerHandler = new Uno.UI.Wasm.WasmHttpHandler();
#else
            var innerHandler = new HttpClientHandler();
#endif
            _httpClient = new HttpClient(innerHandler);

有关使用 HttpClient 的示例,请参阅 https://github.com/unoplatform/uado

【讨论】:

  • 我添加了代码,它给了我一个响应 200,但我得到了一个 ApiException:无法反序列化控制台中的响应正文流。我是否需要以某种适用于 WASM 的方式对其进行反序列化?(这一切都适用于 UWP)
  • 我能够使用普通的 HttpClient 获得连接。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
  • 2015-09-10
  • 1970-01-01
  • 2017-02-09
相关资源
最近更新 更多