Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Rx.DOM.ajax does not URL encode object body content #125

Open
muj-beg opened this issue Nov 10, 2016 · 3 comments
Open

Rx.DOM.ajax does not URL encode object body content #125

muj-beg opened this issue Nov 10, 2016 · 3 comments

Comments

@muj-beg
Copy link

muj-beg commented Nov 10, 2016

Calling Rx.DOM.ajax() with content type set to application/x-www-form-urlencoded and a body such as { name1: "value1&", name2: "value2" } sends the HTTP data as: name1=value1&&name2=value2. This is because the RxJs Ajax code does not URL encode values when converting a object body content to string payload.

@matias-casal
Copy link

+1

@gilbarbara
Copy link

gilbarbara commented May 16, 2017

@muj-beg did you found a way to fix this?
Instead of passing an object to the body property, I just passed a string using a deparam module, like qs or query-string

@muj-beg
Copy link
Author

muj-beg commented May 19, 2017

@gilbarbara We ended up doing this:

const shouldUrlEncodeContent =
     request.body && typeof request.body !== 'string' && 
     request.headers && typeof request.headers['Content-Type'] === 'string' &&  
     request.headers['Content-Type'].indexOf('application/x-www-form-urlencoded') === 0;
        
if (shouldUrlEncodeContent) 
   request.body = QueryString.stringify(request.body);     

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