dotnetcore / WebApiClient

A REST API library with better functionality, performance, and scalability than refit
https://webapiclient.github.io/
MIT License
2.02k stars 442 forks source link

在 Blazor(wasm) 中运行报错 #109

Closed fixnil closed 4 years ago

fixnil commented 4 years ago

如题,目前只是按照 README 进行了最简单的使用体验(一个 Get 接口);

具体报的错是 Resolve 时设置 UseProxy 属性出错,平台不支持,具体堆栈信息如下:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Property UseProxy is not supported.
System.PlatformNotSupportedException: Property UseProxy is not supported.
  at System.Net.Http.HttpClientHandler.set_UseProxy (System.Boolean value) <0x2eeb288 + 0x0000c> in <filename unknown>:0 
  at WebApiClient.DefaultHttpClientHandler..ctor () <0x2edbd88 + 0x0000c> in <filename unknown>:0 
  at WebApiClient.HttpApiFactory.CreateHttpHandler () <0x2edba08 + 0x00024> in <filename unknown>:0 
  at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) <0x2ed2f28 + 0x00062> in <filename unknown>:0 
  at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) <0x2ed2e48 + 0x00044> in <filename unknown>:0 
  at System.Lazy`1[T].CreateValue () <0x2ed2d20 + 0x000b8> in <filename unknown>:0 
  at System.Lazy`1[T].get_Value () <0x2ed29e8 + 0x0000c> in <filename unknown>:0 
  at WebApiClient.HttpApiFactory.CreateHttpApi () <0x2ed2870 + 0x0000c> in <filename unknown>:0 
  at WebApiClient.HttpApi.Resolve (System.String name) <0x2ed1e60 + 0x00042> in <filename unknown>:0 
  at WebApiClient.HttpApi.Resolve[TInterface] (System.String name) <0x2ed1d28 + 0x00004> in <filename unknown>:0 
  at WebApiClient.HttpApi.Resolve[TInterface] () <0x2ed1c60 + 0x0000a> in <filename unknown>:0 
  at WebApiClientToBlazor.Pages.Index.OnInitializedAsync () [0x0001a] in C:\Users\depin\source\repos\WebApiClientToBlazor\WebApiClientToBlazor\Pages\Index.razor:17 
  at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2dc6728 + 0x0013a> in <filename unknown>:0 
xljiulang commented 4 years ago

WebApiClient.JIT在跨平台体验一致性做了很多设置,但如果某些特殊平台不完全支持标准函数的话,就出现这样的问题,对于这个具体问题,在HttpApiFactory传入默认的Handler就不会触发调用了UserProxy属性。

xljiulang commented 4 years ago

@Dudeping 下载WebApiClientCore这个包试试