I'm trying to get my Blazor Web-App to display data from a Http POST sent through CURL, But I'm having trouble with anti-forgery validation.My Blazor page source:
@page "/Data"@inject HttpClient httpClient<PageTitle>Data</PageTitle><h1>POST:</h1><p>@(rqData != null?rqData:"NoData!") </p>@code { private string? rqData; protected override async Task OnInitializedAsync() { await GetData(); } private async Task GetData() { try { // Send POST request HttpResponseMessage response = await httpClient.PostAsync("https://localhost:7084/data", null); // Check if request was successful response.EnsureSuccessStatusCode(); // Read response content rqData = await response.Content.ReadAsStringAsync(); } catch (HttpRequestException e) { // Handle any errors rqData = "Error: " + e.Message; } }}
And I'm testing this with a sample CURL request:
curl -X POST https://localhost:7084/data -d "key=value"
But this method doesn't really comply with Blazor's default Anti-forgery token system in any way, and thus, fails. What would be the proper way to handle these requests with token validation on both, the Blazor web-app side of things and when testing it's functionality with CURL. Sorry if this question is noob-ish, I'm very new to this level of interconnectivity within Blazor Apps.