I call the api endpoint in MVC 6 WebAPI:
POST http://localhost:57287/mytestapi/testentity/ HTTP/1.1 Accept: application/json X-APIKey: 00000000-0000-0000-0000-000000000000 Content-Type: application/json; charset=utf-8 Host: localhost:57287 Content-Length: 1837 Expect: 100-continue Connection: Keep-Alive
In the body, I have a serialized test json object.
I have an error in the code of the entity controller, and the api returns a 500 "Server Error" response. I know that the error will be fixed, but the problem I need help with is that the API returns HTML instead of a json-serialized exception object - Json is what I expect: this is what the old webapi will return. I ported the encoding from an old test project, which, as I know, works.
So why does MVC 6 WebAPI return html and not json? Is there some kind of configuration I need to do?
EDIT: I added Accept: application / json to the headers as suggested by @danludwig, however this did not solve the problem, I still got the html error page.
I looked at my StartUp.cs and found:
if (env.IsDevelopment()) { //app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); }
in the ConfigureApp method. I tested the app app.UseDeveloperExceptionPage (); commented out. This prevented the html error page from returning to the api response body, however I still don't get the serialized json object.
source share