我正在尝试在 Blazor 服务器中执行 http Post 请求。我尝试发送用户名和密码
这是我进行 Web Api 调用的部分:
private IEnumerable<yolo> test = Array.Empty<yolo>();
private bool getBranchesError;
private bool shouldRender;
protected override async Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Post,
"https://url.com");
request.Headers.Add("Accept", "application/vnd.github.json");
request.Headers.Add("User-Agent", "HttpClientFactory-Sample");
var client = ClientFactory.CreateClient();
var response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
using var responseStream = await response.Content.ReadAsStreamAsync();
test = await JsonSerializer.DeserializeAsync
<IEnumerable<yolo>>(responseStream);
}
else
{
getBranchesError = true;
}
shouldRender = true;
}
public class yolo
{
[JsonPropertyName("name")]
public string Name { …Run Code Online (Sandbox Code Playgroud)