How to add and get Header values in WebApi

前端 未结 10 1606
既然无缘
既然无缘 2020-12-02 05:45

I need to create a POST method in WebApi so I can send data from application to WebApi method. I\'m not able to get header value.

Here I have added header values in

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 06:36

    For .NET Core:

    string Token = Request.Headers["Custom"];
    

    Or

    var re = Request;
    var headers = re.Headers;
    string token = string.Empty;
    StringValues x = default(StringValues);
    if (headers.ContainsKey("Custom"))
    {
       var m = headers.TryGetValue("Custom", out x);
    }
    

提交回复
热议问题