Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Help please, how to set the default paramSerializer to $httpParamSerializerJQLike? #13130

Closed
KingMario opened this issue Oct 20, 2015 · 2 comments

Comments

@KingMario
Copy link

I try the following config to setup $httpProvider defaults, but the $httpParamSerializerJQLike is not invoked when I post a request using $http.post(myUrl, {phone: '18812222'}).then(func1, func2);. The form data in the post request is a JSON string {"phone":"18812222"}, which is not serialized JQLikely.

myApp.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    $httpProvider.defaults.paramSerializer = '$httpParamSerializerJQLike';
}]);

Thanks

@KingMario KingMario changed the title Please, how to set the default paramSerializer to $httpParamSerializerJQLike? Help please, how to set the default paramSerializer to $httpParamSerializerJQLike? Oct 21, 2015
@armanforghani
Copy link

I have the same problem using Angular 1.4.6.

@gkalpak
Copy link
Member

gkalpak commented Oct 27, 2015

The paramSerializers are for serializing...params (not the payload/data of the request).
I.e. $http.get('/url', {params: {foo: 'bar'}}).

Currently, automatically serializing the data is not supported (but you could use the provided paramSerializers to serialize it manually).

Closing as this works as expected atm and the feature request for adding support for serializing data is tracked in #6039.

BTW, you can use a paramSerializer to serialize payload/data, but you need a little setup and it is not guarranteed to work in all edge-cases, as it hasn't been designed/tested for that purpose.
See #6039 (comment).

@gkalpak gkalpak closed this as completed Oct 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants