Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
183
rated 0 times [  187] [ 4]  / answers: 1 / hits: 15585  / 10 Years ago, mon, june 23, 2014, 12:00:00

I am trying to make a request against a php server that is constructing the url like this:



website.com/?q=help&q=moreHelp&q=evenMoreHelp



How do I use superagent to pass the same query with multiple values?



I've tried this:



req.get('website.com').query({q:'help',q:'moreHelp',q:'evenMoreHelp'}).end(...)



But I'm not sure it is actually sending all three 'q' values. What am I supposed to do to make sure they all get sent?


More From » node.js

 Answers
33

You definitely will not see all three q values when you pass the query in the manner you are trying, because you are making a JavaScript object there and yes, there will only be one q value:



$ node
> {q:'help',q:'moreHelp',q:'evenMoreHelp'}
{ q: 'evenMoreHelp' }


Superagent allows query strings, as in this example straight from the docs:



request
.get('/querystring')
.query('search=Manny&range=1..5')
.end(function(res){

});


So if you pass the string 'q=help&q=moreHelp&q=evenMoreHelp' you should be okay. Something like:



req.get('website.com').query('q=help&q=moreHelp&q=evenMoreHelp').end(...)


If this is too ugly, you can try (WARNING: I have not tried this):



req.get('website.com')
.query({ q: 'help' })
.query({ q: 'moreHelp' })
.query({ q: 'evenMoreHelp' })
.end(...);

[#70466] Friday, June 20, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maya

Total Points: 418
Total Questions: 116
Total Answers: 112

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
maya questions
Sun, Jul 4, 21, 00:00, 3 Years ago
Tue, Dec 22, 20, 00:00, 4 Years ago
Fri, Nov 6, 20, 00:00, 4 Years ago
Wed, Jul 29, 20, 00:00, 4 Years ago
Tue, Apr 21, 20, 00:00, 4 Years ago
;