简体   繁体   中英

How to get the Header from a request in a API with C#

I'm building one REST API to my business and I need to get the values from the header in the request but I don't know how?

I need to create a filter in the header and validate this.

Someting like this: header: filterDate = false/true

public CarrierController(ICarrierAppService appService, ICarrierEAppService EAppService)
        {
            _appService = appService;
            _EAppService = EAppService;
        }

        /// <summary>
        /// Create or update a carrier
        /// </summary>
        /// <param name="messageUniqueId">Message Id from external system </param>
        /// <param name="carrierDto">Carrier to create</param>
        /// <returns>Carrier created or updated</returns>
        [HttpPost]
        [ProducesResponseType (typeof (CarrierDto), 200)]
        [ProducesResponseType (typeof (ErrorResponse), 400)]
        public async Task<IActionResult> Post (bool isBusinessE, string messageUniqueId, [FromBody] CarrierDto carrierDto) {

                carrierDto = await _EAppService.UpsertCarrierAsync (carrierDto);
                return CreateResponseOnPost (carrierDto, _name);

        }

Please help me to level up:'/ I'm only a little noob:'/

Inside your method named Post , you can get to the headers of the request by using Request.Headers dictionary object. For example: Request.Headers["filterDate"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM