imaginecreate
imaginecreate

Reputation: 11

ASP.NET Core 5 MVC : HTTP POST request to handle query string parameter

I have been tasked with writing Http POST method to process incoming webhook data and I have been able to achieve that but to actually start receiving I have to first subscribe to Webhook event by validating the url and for that I also have to capture query string parameter passed in POST request which is where I am having issues.

Below method signature is able to capture header and body and then implementation processes the data.

[HttpPost]
public IActionResult Callback([FromHeader(Name = "headerSignature")] string signature, [FromBody] WebHookEventData eventData)

However I also need to enable this to capture data coming from query string. For example below is the url with query string and when I pass that as POST request from Postman it throws error 415 unsupported media type:

https://webhoook.example.com/webhook/callback?centre.challenge=test

enter image description here

How do I capture query parameter in POST request?

Upvotes: 0

Views: 686

Answers (1)

Ali Mahmoodi
Ali Mahmoodi

Reputation: 1204

Simple you can use HttpContext like this:

var queryString = HttpContext.Request.QueryString ;

and if you like to Address a special QueryString do it this way :

var queryStringId = HttpContext.Request.Query["id"] ;

Hope it helps ;)

Upvotes: 0

Related Questions