HTTP 406 Response with "ng-include" due to "Accept" header

476 views
Skip to first unread message

RedBaaron

unread,
Apr 21, 2015, 11:44:53 PM4/21/15
to ang...@googlegroups.com
I am using AngularJS v1.3.15.

I have a relatively simple app that is using ng-include as follows:

<div ng-include src="'app/layout/shell.html'"></div>

I am using IIS as the web server and am tracing the calls that are made from my browser using Fiddler.    In Fiddler I see that the request for the page referenced in the ng-include comes back with a HTTP status code of 406 (Not Acceptable).   The server also give additional details to the error that include "The request was rejected because it contained an Accept header for a MIME type that is not supported for the requested file extension.".   In the "Raw" view in Fiddler I can see that the header contains "Accept: application/json;odata=verbose;"   If I copy the Raw request into the "Composer" in Fiddler and change the header to have "Accept:  text/html", then everything works and I get the HTML of the page just fine.

So... what am I doing wrong that is causing Angular to add the "Application/json" and how can I change it to use "text/html"?   

Thanks in advance!!!
--Aaron

Sander Elias

unread,
Apr 22, 2015, 12:13:06 AM4/22/15
to ang...@googlegroups.com

Hi RedBaaron,

That is strange indeed. I’m not sure this is gonna help, but can you try it?

<div ng-include="'app/layout/shell.html'"></div>

does that make a difference?
If not, is there a $http interceptor in your code somewhere?

Regards
Sander

RedBaaron

unread,
Apr 22, 2015, 12:28:21 AM4/22/15
to ang...@googlegroups.com
Hand slap on forehead!!!!!  Just searched my code and found:  $http.defaults.headers.common.Accept = 'application/json;odata=verbose;';

Why in the heck I did that I guess I will figure out when something else breaks. Why this application worked on a different host is also beyond me.   Thank you very much!!

Sander Elias

unread,
Apr 22, 2015, 12:32:12 AM4/22/15
to ang...@googlegroups.com
RedBaaron,

Happens to all of us, from time to time! :)

Regards
Sander
Reply all
Reply to author
Forward
0 new messages