Skip to content
Advertisement

Send Post request to Node.js with PHP cURL

I am trying to send a post request through PHP cURL to my node.js server to then emit a message to the client. The server is working and setup as follows:

JavaScript

and my PHP is as follows:

JavaScript

The console says that json.message is undefined. Why is it undefined?

Advertisement

Answer

You’re using querystring.stringify() incorrectly. See the documentation on querystring’s methods here:

http://nodejs.org/docs/v0.4.12/api/querystring.html

I believe what you want is something like JSON.stringify() or querystring.parse(), as opposed to querystring.stringify() which is supposed to serialize an existing object into a query string; which is the opposite of what you are trying to do.

What you want is something that will convert your fullBody string into a JSON object.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement