[$http:badreq] The request is not properly formatted. $http transformRequest default in AngularJS 1.6
0 reputation · 11 Jul 2024, 14:16 UTC
AngularJS 1.6 changed the default $http transformRequest behavior for plain JavaScript objects. The documented change means requests are JSON stringified where earlier releases used form-encoded serialization. This creates compatibility uncertainty with backends that still expect form-encoded payloads.
When a backend that expects form-encoded data receives JSON, the response may be a client error with a non-JSON body. $http's transformResponse attempts to parse responses as JSON, and under specific conditions the service surfaces the error string "[$http:badreq] The request is not properly formatted.". The decision to keep the new default without a documented opt-out remains an open design question.
What response status and body conditions cause $http to emit [$http:badreq] The request is not properly formatted. in AngularJS 1.6? Is the default transformRequest change configurable via $httpProvider without providing a custom serialization function? Does the error originate from transformResponse parsing failure or from request formatting validation?