I am developing a Blazor WASM application in .NET6.
In Blazor is possible to make a call from Client component
@code {
await Http.GetFromJsonAsync<Model>("/api/model/view/" + modelId);
}
that triggers a controller in the Server project
[HttpGet, Route("/api/model/view/{id:int}")]
public async Task<Model> GetModel(int modelId)
{
try { return await Task.FromResult(_IModel.GetModel(id)); }
catch { throw; }
}
But is it possible to post from a client project via cs class like following:
HttpClient httpClient = new HttpClient();
var content = new StringContent(JsonConvert.SerializeObject(authcookie_value), Encoding.UTF8, "application/json");
httpClient.BaseAddress = new(Parameters.urlstring);
var result = httpClient.PostAsync("/api/auth/refresh", content);
And the controller on the Server project to be fired:
[HttpPost, Route("/api/auth/refresh")]
public IActionResult AuthRefresh(StringContent httpContent)
{
try
{
}
catch { throw; }
}
The above example is not working because the controller is not fired when the call is thiggered. Any ideas?