question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

post(url, data) does not send any data

See original GitHub issue

superagent allows the following syntax:

request(app).post('/url', { foo: 'bar' })

This should set the content-type to json and send the JSON data in the request body.

With supertest the above syntax results in no content-type and no body.

testcase:

  it('.post should work with data', function (done) {
    var app = express();

    app.use(express.bodyParser());

    app.post('/', function(req, res){
      res.send(req.body.name);
    });

    request(app)
    .post('/', { name: 'tobi' })
    .expect('tobi', done);
  })

Thanks.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:18
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

26reactions
mikkercommented, Feb 6, 2015

Adding .type('form') fixed this for me.

25reactions
montarocommented, Jan 27, 2016

This worked for me

import bodyParser from 'body-parser';
app.use(bodyParser.json());
Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript - POST to URL not sending data - Stack Overflow
I'm trying to send POST data from a Chrome extension to a website controlled by me. However, when sending the POST data I...
Read more >
POST requests don't send any data · Issue #831 - GitHub
I can't send any data with POST. I'm on Normal mode, raw, JSON, with the data {"hello": "world"}. My server is receiving empty...
Read more >
Building requests | Postman Learning Center
You can send requests in Postman to connect to APIs you are working with. Your requests can retrieve, add, delete, and update data....
Read more >
Sending form data - Learn web development | MDN
The data is appended to the URL as a series of name/value pairs. After the URL web address has ended, we include a...
Read more >
HTTP Methods GET vs POST - W3Schools
GET is used to request data from a specified resource. Note that the query string (name/value pairs) is sent in the URL of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found