How to add and get Header values in WebApi

前端 未结 10 1608
既然无缘
既然无缘 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:50

    You need to get the HttpRequestMessage from the current OperationContext. Using OperationContext you can do it like so

    OperationContext context = OperationContext.Current;
    MessageProperties messageProperties = context.IncomingMessageProperties;
    
    HttpRequestMessageProperty requestProperty = messageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
    
    string customHeaderValue = requestProperty.Headers["Custom"];
    

提交回复
热议问题