Note that there are some explanatory texts on larger screens.

plurals
  1. POExpress js body parser not working?
    primarykey
    data
    text
    <p>I have the following in my node server using express (truncated to the important parts):</p> <pre><code>var app = express.createServer(); app.all(/test/,function(req,res){ console.log(req.headers); console.log(req.body); res.send(""); }); function appStart(cobrands){ app.configure(function(){ app.use(express.bodyParser()); app.use(express.cookieParser()); app.use('/min',express.static('../min')); app.use('/js',express.static('../js')); app.use('/css',express.static('../css')); app.use('/img',express.static('../img')); }); app.listen(8080); } </code></pre> <p>I then have a simple form that calls out to localhost:8080 like so:</p> <pre><code>&lt;form action="http://localhost:8080/test" method="post"&gt; &lt;input type="hidden" name="test" value="testing"/&gt; &lt;input type="submit" name="submit" value="to node"/&gt; &lt;/form&gt; </code></pre> <p>But express.bodyParser doesn't seem to be doing anything, and req.body is undefined. Here's the output of the <code>console.log</code>s: </p> <pre><code>// req.headers { host: 'localhost:8080', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 Safari/534.48.3', 'content-length': '27', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', origin: 'file://', 'content-type': 'application/x-www-form-urlencoded', 'accept-language': 'en-us', 'accept-encoding': 'gzip, deflate', cookie: '', connection: 'keep-alive' } // req.body undefined </code></pre> <p>Note: <code>content-type</code> is correctly defined as <code>application/x-www-form-urlencoded</code> as it should be for bodyParser to work, and I've verified that it's coming over by popping open the debug tools in Safari and verifying that the form data is present.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload