在我的 API 中,我试图像这样返回 303 状态
HttpContext context = _contextService.GetHttpContext();
context.Response.Clear();
context.Response.Headers["Location"] = $"{baseUrl}/api/v1/Report/reports/{existingReport.Id}";
GetReportResponse response = ReportController.GetReportResponseFromReport(existingReport);
return StatusCode(StatusCodes.Status303SeeOther, response);
但是在客户端中,响应是 404 并且未设置位置标头。
编辑:我认为问题是由于 303 响应导致的自动重定向,但我不确定如何让客户端在重定向时添加凭据。
看来您需要使用凭据,但这似乎也不起作用
HttpClientHandler handler = new HttpClientHandler { Credentials = credentialCache, UseDefaultCredentials=true, PreAuthenticate=true };
HttpClient client = new HttpClient(handler);