0

I know it is wired, but server side already implemented without URI-encoded/decoded feature, and cannot fixed.

So I should use the characters in URL on GET query, without any encoded.

When I request the URL like:

https://example.com/check?id=myAccount&password=qwerty!@#

then http(s) module automatically changed to

https://example.com/check?id=myAccount&password=qwerty!@

Because of that, I cannot send data as I want. How can I do it without other NPM module?

I checked document also, but I cannot find answer.

https://nodejs.org/api/http.html#http_http_request_url_options_callback

I used below code on Node.js.

// Example : https://example.com/check?id=myAccount&password=qwerty!@#
(_url, params) => {
    return new Promise((resolve, reject) => {
        if (params) {
            let queryParams = `?`;
            for (let key in params) {
                const value = params[key];
                queryParams += `${key}=${value}&`;
            }
            queryParams = queryParams.slice(0, -1);
            _url += queryParams;
        }


        const options = {
            method: `GET`,
        }

        const req = https.request(_url, options, (res) => {
            // When I checked it, request URL is changed to https://example.com/check?id=myAccount&password=qwerty!@
            // (Removed "#" automatically)
            // console.log(req)

            let data = ``;
            res.on(`data`, (d) => {
                data += d.toString();
                process.stdout.write(d);
            });


            res.on(`end`, () => {
                // process.stdout.write(d);
                resolve(data);
            });
        });

        req.on(`error`, (e) => {
            console.error(e);
        });
        req.end();

    });
}
Park
  • 85
  • 8

1 Answers1

0

You cannot access it, because it never arrives on your server. Http clients (browsers, or curl) do not send fragments (the # part of URL).

So if you make a request to http://test.com/path#myCustomData what gets sent is only http://test.com/path.

https://stackoverflow.com/a/9967728/5521670

Šimon Kocúrek
  • 1,591
  • 1
  • 12
  • 22