httpPost gives a blank body

Hey all, I am having some trouble with the httpPost function sending an empty body to my server application. This project is from The Coding Train's 8.x (in particular 8.7) tutorial series on Express here. Here also is a link to my github repo with the code. The issue is something between the sketch.js and server.js files. Thanks for any help!

Tagged:

Answers

  • If you are able to, try out my fork here: https://github.com/limzykenneth/p5.js

    I'm in the process of fixing bugs related to this part of the library, any help with testing is greatly appreciated.

  • Hi, I'm using an apache server where lies a php which only returns the data received using "echo var_dump($_POST)". An sketch sends data with httpPost to the php page, but always the content of the $_POST variable is something like this:

    "array(0) {↵}↵"

    I don't know if this happens due a problem of httpPost function or by me.

    I'm newbie on github and I don't know how can I try out your fork.

  • Unfortunately it probably is due to the bug in httpPost, it just isn't sending data to the server, that's why you get an empty array in PHP. If you want to try out my fork, you can follow instructions here but where it says to "Fork and clone this library", clone my fork instead with this command git clone https://github.com/limzykenneth/p5.js.git. The follow the rest of the instructions and you should have a fresh build in the lib folder.

    Alternatively, a new version with a fix is expected to come out next week, as soon as my fixed is merged into the library.

  • Thank you very much.

    I'm having the same problem.

    I have a basic html (with a simple button and an intput text) which load the sketch too. Button and input text are captured from sketch, when button is clicked httpPost function is executed like this:

    httpPost("action.php","text","hello",response,error);

    I have a php file (action.php) that echoes the POST:

    var_dump($_POST)

    Always it responses with Array{0}

    If instead of using httpPost function I use "form" tag in the html file, this simple example works. But I need to use httpPost function in order to know the response.

    What I doing bad?

    Thanks

  • Finally it works. I've used

    $post = file_get_contents('php://input');

    Thank you very much.

Sign In or Register to comment.