【发布时间】:2021-10-25 00:03:59
【问题描述】:
我的 Blazor 页面代码:
private async Task OnSendSMSClick()
{
var request = new HttpRequestMessage(HttpMethod.Post, baseAddress);
request.SetBrowserRequestMode(BrowserRequestMode.NoCors);
request.SetBrowserRequestCache(BrowserRequestCache.NoCache);
HttpContent content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("client_id", client_id),
new KeyValuePair<string, string>("client_secret", client_secret)
});
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
request.Content = content;
RequestOutput = request.ToString();
HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead);
ResponseOutput = response.StatusCode.ToString();
}
response 总是返回空,尽管我在 Fiddler 上看到返回了实际结果。在 Google Chrome 上,我看到服务器以正确的标头响应 200,但不知何故 Chrome 显示“加载响应数据失败”。
Chrome 上没有错误,我收到 200 响应,但不知何故无法显示响应内容:
而且你可以在调试器中看到响应对象是空的..
我该如何解决这个问题,我在这里缺少什么?
谢谢!
【问题讨论】:
标签: blazor httpclient webassembly httpresponsemessage sendasync