Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
req.body undefined in POST request
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
soeren  
View profile  
 More options Oct 30 2010, 6:27 pm
From: soeren <soeren.roer...@googlemail.com>
Date: Sat, 30 Oct 2010 15:27:26 -0700 (PDT)
Local: Sat, Oct 30 2010 6:27 pm
Subject: req.body undefined in POST request
Hi everyone,

I seem to have a problem with req.body being "undefined" when using a
POST request. Im using expresso to do the POST:

-- snip
assert.response(server, {
    url: '/',
    method: 'POST',
    data: '{"somevar": "somestring"}'
 }, {
     body: 'someresponse'

});

-- /snip

express = require('express').
server = express.createServer();

server.configure(function() { server.use(express.bodyDecoder()); };

server.post('/', function(req, res) {
        console.log(req.body);

});

I'm using version 1.0.0rc4.
Any pointers would be greatly appreciated.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vision media [ Tj Holowaychuk ]  
View profile  
 More options Oct 30 2010, 9:47 pm
From: "vision media [ Tj Holowaychuk ]" <t...@vision-media.ca>
Date: Sat, 30 Oct 2010 18:47:06 -0700
Local: Sat, Oct 30 2010 9:47 pm
Subject: Re: [Express-js] req.body undefined in POST request

few pointers:

   1.  you are not required to use app.configure() if you dont plan on (or
   need) different environments
   2. you need to set the Content-Type to either application/json or
   application/x-www-form-urlencoded, these are the two that bodyDecoder parses

On Sat, Oct 30, 2010 at 3:27 PM, soeren <soeren.roer...@googlemail.com>wrote:

--
Tj Holowaychuk
Vision Media
President & Creative Lead

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
soeren  
View profile  
 More options Oct 31 2010, 3:32 am
From: soeren <soeren.roer...@googlemail.com>
Date: Sun, 31 Oct 2010 00:32:44 -0700 (PDT)
Local: Sun, Oct 31 2010 3:32 am
Subject: Re: req.body undefined in POST request
Aah ok, makes sense and works, thanks a lot.

On Oct 31, 2:47 am, "vision media [ Tj Holowaychuk ]" <t...@vision-


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
michael  
View profile  
 More options Nov 1 2010, 5:17 pm
From: michael <m...@zive.at>
Date: Mon, 1 Nov 2010 14:17:03 -0700 (PDT)
Local: Mon, Nov 1 2010 5:17 pm
Subject: Re: req.body undefined in POST request
I've got the same problem:

http://gist.github.com/658885

Thanks,

Michael

On Oct 31, 8:32 am, soeren <soeren.roer...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
michael  
View profile  
 More options Nov 1 2010, 5:48 pm
From: michael <m...@zive.at>
Date: Mon, 1 Nov 2010 14:48:12 -0700 (PDT)
Local: Mon, Nov 1 2010 5:48 pm
Subject: Re: req.body undefined in POST request
Worked, when I put the app.use calls in front.

However for me, nested params are not parsed. For the user example
(taken from the Express.js documentation) I get:

{ 'user[name]': 'adsf', 'user[email]': 'dsfa' }

Thus, req.body.user doesn't work. Is this intended?

-- Michael

On Nov 1, 10:17 pm, michael <m...@zive.at> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vision media [ Tj Holowaychuk ]  
View profile  
 More options Nov 1 2010, 5:53 pm
From: "vision media [ Tj Holowaychuk ]" <t...@vision-media.ca>
Date: Mon, 1 Nov 2010 14:53:59 -0700
Local: Mon, Nov 1 2010 5:53 pm
Subject: Re: [Express-js] Re: req.body undefined in POST request

if you are using node 0.3.x then that is what you will get, until I start
supporting the 0.3.x branch

--
Tj Holowaychuk
Vision Media
President & Creative Lead

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
michael  
View profile  
 More options Nov 1 2010, 8:22 pm
From: michael <m...@zive.at>
Date: Mon, 1 Nov 2010 17:22:50 -0700 (PDT)
Local: Mon, Nov 1 2010 8:22 pm
Subject: Re: req.body undefined in POST request
I think I'll go with application/json for now. Thanks a lot!

On Nov 1, 10:53 pm, "vision media [ Tj Holowaychuk ]" <t...@vision-


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Galea  
View profile  
 More options Dec 10 2010, 9:54 pm
From: Luke Galea <ldga...@gmail.com>
Date: Fri, 10 Dec 2010 18:54:57 -0800 (PST)
Local: Fri, Dec 10 2010 9:54 pm
Subject: Re: req.body undefined in POST request
Hi all,

I'm running into this issue. I am using application/json, but req.body
== undefined. Node version is v0.2.5, Expresso is 0.70, Express is
1.0.

Express:
app.configure(function(){
...
  app.use(express.bodyDecoder());
...
app.post('/observations', function(req, res) {
  console.log(req.body);
...

Expresso:
  'POST /observations': function(){
    assert.response(app,
      { url: '/observations', method: 'POST',
        'Content-Type': 'application/json',
        data: JSON.stringify({ observation: { time_label: 'something
' } })
      },
      { status: 200, headers: { 'Content-Type': 'text/html;
charset=utf-8' }},
      function(res){
        assert.includes(res.body, 'show-observation-page');
      });
  }

Any ideas? Thanks in advance!

On Nov 1, 7:22 pm, michael <m...@zive.at> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tjholowaychuk  
View profile  
 More options Dec 10 2010, 11:52 pm
From: tjholowaychuk <tjholoway...@gmail.com>
Date: Fri, 10 Dec 2010 20:52:18 -0800 (PST)
Local: Fri, Dec 10 2010 11:52 pm
Subject: Re: req.body undefined in POST request
weird man, looks totally fine, will try that when I have a chance

On Dec 10, 6:54 pm, Luke Galea <ldga...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »