Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Need a way to not escape querystrings #409

Closed
blakevanlan opened this Issue Jan 9, 2013 · 6 comments

Comments

Projects
None yet
4 participants

I am using the Bing Search REST API and the querystring parameters for "top" and "skip" are actually "$top" and "$skip". This causes a problem when using this library because all of the query strings are escaped prior to the request. Bing, of course, doesn't understand the parameters when they are escaped (when "$top" -> "%24top").

Pretty lame that Bing requires this but I think it could be a useful feature.

Owner

mikeal commented Jan 9, 2013

do we escape them or does the querystring library escape them or does the url modules escape them?

Looks like I was having a different issue behind the scenes that I didn't realize. Apparently, Bing requires you to wrap the query in double quotes? Dumb. Anyways, if the qs option is used then the querystrings are escaped (even ones included in uri option originally, which was also tripping me up). This is good enough in my opinion. Maybe mention it in the readme?

@mikeal mikeal closed this Aug 27, 2014

I have a similar case, I'm doing a request like the following:

var request = require('request');
request('http://test.com?name=mé')

That query parameter seems to be escaped I need to send the unescaped version. Is there a way?

@mikeal any guess?

I've also tried the following but no luck:

var request = require('request');
var url = require('url');

var hitMe = url.parse('http://test.com?name=mé');
request({uri: hitMe})

Never mind, I finally found a way:

var request = require('request');

var options = {
        uri : '/path',
        baseUrl: 'http://test.com',
        qs : { name : ''} ,
        useQuerystring : true,
        qsStringifyOptions : {
            options: {
                encodeURIComponent : function (obj) {

                    var queryString = '';

                    for (var key in obj) {
                        queryString += '&' + key + '=' + obj[key];          
                    }

                    return queryString;
                }
            }
        }
};

request(options)
Owner

simov commented Oct 29, 2015

Thanks for sharing your solution, @jonathanwiesel 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment