Webduino receives POST parameters from curl, but not from Node

Here's the code running on Arduino using the Webduino library :

void handleConfigRequest(WebServer &server, WebServer::ConnectionType type, char *, bool) {

// POST request to receive new config
if (type == WebServer::POST) {

  bool repeat;
  char name[16], value[50];

  do {
      // Returns false when no more params to read from the input
      repeat = server.readPOSTparam(name, 16, value, 50);

      if (strcmp(name, "dName") == 0) {
        strcpy(deviceName, value);
        Serial.println(value);
      }
  } while (repeat);
}

      

Works as expected (and prints "Test" over serial) when running the following from curl on the command line:

curl http://10.0.1.141/config -d "dName = Test"

I also tested a simple HTML form that also works and prints "Test" over serial on submission:

<form action="http://10.0.1.141/config">
  <input type="text" name="dName" value="test">
  <input type="submit" value="Send">
</form>

      

However, the following Node.js using request code doesn't work:

var options = {
    url: "http://10.0.1.141/config",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      "Accept": "*/*",
      "User-Agent": "TestingScript"
    },
    form: {dName: "Test"}
  }

  request.post(options, function(error, response, body) {
    console.log(error, response, body)
  })

      

Using Node code, the Arduino confirms the HTTP POST request (in this case, flashing the LED), but does not print "Test" to serial.

I pointed to curl and my Node code in the requestb.in page, and you can see the requests themselves seem to be the same (bottom is curl, top is mine):

Requestbin

Any suggestions?

+3


source to share


1 answer


At the end, I replaced the Node code request

with the following jQuery:

$.ajax({
  type: "POST",
  url: "http://10.0.1.141/config",
  data: {dName: "Test"}
}, function(data( {
  console.log(data)
}

      



It worked fine. It's strange.

0


source







All Articles