Does http module has a bug?


#1

Hi,
After some while i’ve noticed that {N} 4.0 has probably a bug in HTTP: (problems with + Sign)?

This will not work, beacuse POSTed data will have empty space instead of +

http.request({
        //url: 'https://httpbin.org/post',
      
        method: 'POST',
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
// Commented as result of this will be #1
        /*content: JSON.stringify({
                'email': "darren+e@test.uk",
                'password': "password"
        })*/
// Content set as strong, beacuse this results in well formatted string #2
        content: 'email=darren+e@test.uk&password=password'

    }).then(function(response) {
        result = response.content.toJSON();
        console.log('Https.request response', result)
    }).catch(function(error) {
        console.error('Https.request error', error)
    });

#1 is commented for now, as i have some question, but later.

  • For now most important is that email is invalid (+ will be generated as empty space)

  • Second question: JSON.stringify will produce bad result for me:

CONSOLE LOG file:///app/login/login.js:51:20: Https.request response {
"{\"email\":\"darren+e@test.uk\",\"password\":\"password\"}": "",

But content as string produces: (expected result):

CONSOLE LOG file:///app/login/login.js:51:20: Https.request response {
"email": "darren+e@test.uk",
"password": "password",
}

Possible to have this string without doing ugly:
content: 'email=darren+e@test.uk&password=password'

Thank you.


#2

Would be interesting to see the result if you replace “+” with “%2B”.


#3

Yes @vamsi, this will work. But as you know it’s confusing, as i would have to do lots of checks on what user typed in case of replace + with &2B. Cheers.


#4

Agree, http module should take care of the conversion.