0

I am writing a Web API to handle some request. The request url schema is fixed. I cannot modify it. So I have to collect all the necessary info from places like:

  • query string
  • headers
  • cookie
  • web form post data

How can I access all these locations within a Web API action method?

1
  • 1
    Can you not use the Request object to get that information? For example, Request.QueryString. Commented Jul 13, 2014 at 4:58

1 Answer 1

2

The Query String and Post Data information can be received as Web API Method parameters (preferred way, since Web API will do the necessary binding for you) Use the FromBody or FromUri attributes on the method parameters)

OR

you could access it using the old fashioned way of Request object. you have access to the http request using the Request object in your Web API Action method. you can get all the information using..

Request.QueryString
Request.Form["name"]
Request.Cookies
Request.Headers
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.