Blazor WebAssembly exception while calling REST API calls - WebAssembly.JSException: TypeError: Failed to fetch at WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler.doFetch
See original GitHub issueI am trying to call REST API call from web Blazor WebAssembly using the following code
var userInfo = new ValidateUserRequest { UserName = UserName, Password = password };
var response = await Http.PostJsonAsync<string>($"{APIBaseUrl}/Security/ValidateUser", userInfo);
The CORS is enabled in the API.
But when running the application, I got the following error.
WebAssembly.JSException: TypeError: Failed to fetch at WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler.doFetch (System.Threading.Tasks.TaskCompletionSource`1[TResult] tcs, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x22fe098 + 0x00988> in <c4a9717a3f954719acec8a5e4e87c87d>:0 at WebAssembly.Net.Http.HttpClient.WasmHttpMessageHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) <0x22d6978 + 0x00180> in <c4a9717a3f954719acec8a5e4e87c87d>:0 at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) <0x235f0f8 + 0x00278> in <f29c040f027c48c299bba2e6843ac2e0>:0 at Microsoft.AspNetCore.Components.HttpClientJsonExtensions.SendJsonAsync[T] (System.Net.Http.HttpClient httpClient, System.Net.Http.HttpMethod method, System.String requestUri, System.Object content) <0x22a1c88 + 0x00118> in <393f0d2066e842d38b0e8ac688095cf7>:0 at BlazorTestApp2.Shared.Login.ValidateUser (System.String userName, System.String password) [0x0006d] in C:\Repo\BlazorTestApp2\BlazorTestApp2\Shared\Login.razor:83 at BlazorTestApp2.Shared.Login.LoginWithPassword () [0x0003f] in C:\Repo\BlazorTestApp2\BlazorTestApp2\Shared\Login.razor:116
Is this can be fixed anyway?
net version used : 3.1.0-preview4.19579.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
How to resolve "TypeError: Failed to fetch" error on Blazor?
I am trying to send an HTTP request from my Blazor app to my ASP.NET Core API. I have breakpoints everywhere. The application...
Read more >Blazor WebAssembly TypeError: Failed to fetch
So when I use that API endpoint from my Blazor App I received this exception. TypeError: Failed to fetch - at System.Net.Http.BrowserHttpHandler ...
Read more >.NET 6 Blazor WASM: Downloading JSON string fails if ...
JavaScript.JSException: TypeError: Failed to fetch at System.Net.Http.BrowserHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken ...
Read more >[Fix]-How to resolve "TypeError: Failed to fetch" error on Blazor?
Unhandled exception rendering component: TypeError: Failed to fetch. WebAssembly.JSException: TypeError: Failed to fetch. I did a test to make request(s) ...
Read more >How to resolve "TypeError: Failed to fetch" error on Blazor?
webassembly.jsexception: typeerror: failed to fetch. i did a test to make request(s) from my blazor webassembly app to action method with testing data, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have upgraded the version to 3.2.0-preview2.20160.5 and the issue got fixed.
For more info about new upgrade https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-2-release-now-available/
FYI. it’s when connecting to a webapi on HTTP and project was set to configure for HTTPS.
` public async Task<string> GetSomeDataAsync() { var _client = new HttpClient();
`
Create Blazor server project with “Configure HTTPS” NOT ticked. Works Create Blazor server project with “Configure HTTPS” ticked. Works
Create the client web assembly project with “Configure HTTPS” NOT ticked. Works Create the client web assembly project with “Configure HTTPS” ticked. Fail