Using the newer ASP.NET Web API, in Chrome I am seeing XML – how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note: Read the comments of this answer, it can produce a XSS Vulnerability if you are using the default error handing of WebAPI
I just add the following in
App_Start / WebApiConfig.csclass in my MVC Web API project.That makes sure you get JSON on most queries, but you can get
XMLwhen you sendtext/xml.If you need to have the response
Content-Typeasapplication/jsonplease check Todd’s answer below.NameSpaceis usingSystem.Net.Http.Headers.