0

Hi I'm using rails and socket.io in node.js
What I'm trying to do is send a param in rails model using Net::HTTP.post_form
and get the param in node.js file which is server.js

model send.rb

def self.push(userid)
   url = "http://socket.mydomain.com/push"
   res = Net::HTTP.post_form(URI.parse(URI.encode(url)),data)
end

server.js

app.post('/push', function (req, res) {
  console.log(req.param.userid)
});

req variable

req.ip =127.0.0.1
req.protocol= http
req.path = /push
req.host = socket.mydomain.com
req.param

I printed all the values but param always empty is there any solution for this? thanks in advance! :D

Eun Bit Hwang
  • 151
  • 1
  • 9
  • What is `data` in `res = Net::HTTP.post_form(URI.parse(URI.encode(url)),data)`? – Brad Werth Jan 18 '13 at 06:10
  • `data = Hash.new` `data[:userid] = "ebhwang"` by the way I solve this problem using url `url = "http://socket.mydomain.com/push/#{userid}"` `app.post('/push/:userid', function (req, res) { console.log(req.params.userid) });` but still req.param variable is empty – Eun Bit Hwang Jan 18 '13 at 06:41

1 Answers1

0

In Express you can retrieve values posted (HTTP POST) in an HTML form via req.body.searchText if you issue use app.use(express.bodyParser()); Notice that HTML form values come in req.body, not req.params.

Having said that, I am not sure how these values are submitted to the server when you use Socket.io rather than a "normal" HTTP POST on an HTML form.

I realize this is not an exact answer to your question, but wanted to mention how "normal" HTML form values are handled in case it helps and this was way to long to include as a comment.

Hector Correa
  • 26,290
  • 8
  • 57
  • 73