API调用中的GET方法保留标头

问题描述

我有一个asp.net核心应用程序,并且我希望请求标头保留在响应中。 我在邮递员的请求中有3个标头,

Authorization: "Bearer xxxxx"
azet-Accept: application/json"
azet-UseLatestversion: true

这是我在configure方法中设置的内容,

app.Use(
        async (context,next) =>
        {
            context.Response.Headers.Add("X-Content-Type-Options","nosniff");
            context.Response.Headers.Add("Content-Security-Policy","default-src 'self'");
            context.Response.Headers.Add("Referrer-Policy","no-referrer");
            context.Response.Headers.Add(
                "Feature-Policy","accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'");
            context.Response.Headers.Add("X-Frame-Options","DENY");
            await next();
        });

    app.UseHttpsRedirection();

    app.UseRouting();

    app.UseAuthentication();
    app.UseAuthorization();

    app.UseEndpoints(
        endpoints =>
        {
            endpoints.MapControllers();
        }); 

我希望在响应中返回诸如azet-UseLatestversion之类的标题

有什么想法吗?

谢谢

[HttpGet]
[Route("{apiPath}/{*requestUri}")]
public async Task<IActionResult> GetAsync(string apiPath,string requestUri = "")
{
    var queryString = this.Request.QueryString.Value;

    var headers = this.Request
        .Headers
        .ToDictionary(x => x.Key,y => y.Value.FirstOrDefault());

    var response = await this.proxy.GetAsync(
                apiPath,requestUri,queryString,headers,this.GetUserScopes());

    this.logger.LogInformation(
                $"GET statement received from {apiPath} {requestUri} {queryString} {DateTime.Now}.");

    var test = response.Content;

    if (response.HttpStatus != HttpStatusCode.OK)
    {
        this.logger.LogError($"{apiPath} {requestUri} {queryString} {response.HttpStatus}: {response.Content}");

        return this.StatusCode((int)response.HttpStatus,ErrorResponse.GetDefaultMessageForStatusCode((int)response.HttpStatus));
    }
     return this.Content(response.Content?.ToString(),response.ContentType);
 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)