AngularJS $http POST default Content‑Type header – version‑dependent behavior
0 reputation · 17 Nov 2025, 12:55 UTC
AngularJS $http POST default Content‑Type header – version‑dependent behavior
The $http service’s default Content-Type for POST requests changes between AngularJS releases. In 1.4.x the default is application/x-www-form-urlencoded, while 1.5.x and later switch to application/json. This shift is not prominently documented in migration guides, leaving developers uncertain which header is applied in a given project.
When upgrading, code that expects the legacy form‑urlencoded format may send malformed JSON to the server, causing validation failures or unexpected errors. Third‑party modules that rely on the older default may also break unless explicitly reconfigured.
Key constraints: the default header cannot be overridden globally without altering $httpProvider.defaults.headers.post; runtime detection of the AngularJS version is required to decide which default applies; and maintaining backward compatibility across versions is critical for API endpoints that expect key/value pairs.
What is the exact default Content-Type for POST requests in AngularJS 1.4.x versus 1.5.x and newer? How can a project reliably determine the running AngularJS version at runtime to apply the appropriate header? What is the recommended strategy to preserve compatibility when upgrading from 1.4.x to 1.5.x or later?