Here's the code running on the 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);
}
This works as expected (and prints "Test" over serial) when executing the following from curl on the command line:
curl http://10.0.1.141/config -d "dName=Test"
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 the Node code, the Arduino acknowledges the HTTP POST request (in this case, by blinking an LED), but does not print "Test" to serial.
I have pointed both curl and my Node code at a requestb.in page, and you can see that the requests themselves appear to be identical (the bottom one is curl, the top is mine):
Any suggestions?
via Alfo

No comments:
Post a Comment