0

With curl I can send GET-requests with url-encoded parameters as follows:

curl -G http://example.com --data-urlencode "key=val"

How do I do this with supertest / superagent? So far I've tried things like

const response = await request(app)
  .get('/')
  .type('application/x-www-form-urlencoded')
  .send({ key: 'val' });
jorgen
  • 3,425
  • 4
  • 31
  • 53

2 Answers2

3

Try to specify form in type like below:

const response = await request(app)
  .get('/')
  .type('form') // change into `form`
  .send({ key: 'val' });

Ref: https://visionmedia.github.io/superagent/

deerawan
  • 8,002
  • 5
  • 42
  • 51
1

You can make use of it this way:

const response = await request(app)
        .get('/')
        .send('key=val&key2=val2&key3=val3');

Documentation: https://www.npmjs.com/package/supertest (Search 'x-www-form-urlencoded upload')

Nauman Shah
  • 342
  • 2
  • 12