Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acessing querystring and form parameters with Web API

If you choose for whatever reason not to use modelbinding in a HttpPost request, what other ways are there to access the QueryString (HttpGet) or Form parameters (HttpPost)?

Traditionally you could do:

Request.QueryString["Key"]
Request.Form["Key"]
Request["Key"]

I can't seem to find anything similiar in Web API.

like image 589
public static Avatar asked Aug 12 '14 14:08

public static


1 Answers

For query string parameters you can use GetQueryNameValuePairs on a HttpRequestMessage (it's an extension method).

For form data, you need to define the action as this and the raw form data (pre-parameter binding) will be passed to you:

public void Post(NameValueCollection formData)
{
   var value = formData["key"];
}
like image 94
Marcel N. Avatar answered Oct 05 '22 23:10

Marcel N.