Hello, I'm quite new to arduino. I've created my first project, which is a nursecall system running over TCP/IP.
I have created an arduino client to trigger a web service on my server, however I am struggling to successfully send a SOAP request. I've included the part of the code where I am trying to send the SOAP request upon a button being pressed.
Please can anyone see where I am going wrong with this? I'm confused as to what the "length" of the message is. The web service is working fine on the computer. The webservice accepts 4 variables and then inserts them into an MSSQL database.
/////////// EMERGENCY BUTTON BEGIN ///////////
if (emergencyButtonState != lastEmergencyButtonState) {
if (emergencyButtonState == HIGH) {
emergencyButtonPressed = true;
if (client.connect(serverIP, 80)) {
Serial.println("EMERGENCY BUTTON PRESSED");
client.println("POST /ClarocallWebServices.asmx/AddCall HTTP/1.1");
client.println("Host: localhost");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length:3000");
client.println("zonename=ZONE 1&ctxid=CTX001&calltype=EMERGENCY&cstatus=1");
client.stop();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
}
// save current state as the last state for next time through the loop
lastEmergencyButtonState = emergencyButtonState;
/////////// EMERGENCY BUTTON END ///////////
}
You tell the server that you will send 3000 bytes of content but then you send only 57. It will wait until some timeout is reached and will then abort your request. You also didn't terminate the header with a blank line, so the server is actually taking your content as an additional header field. The length is the number of bytes in the body of the request, in your case starting at the "z" of "zonename" and ending at the "1" of "cstatus=1".
Next time you post code, please use code tags as described in the sticky not at the top of the forum.
The space in the zone name is going to cause problems. You need quotes around the name (escaped because the whole string is in quotes). That will affect your count.
The space in the zone name is going to cause problems. You need quotes around the name (escaped because the whole string is in quotes). That will affect your count.
Excuse me but this is wrong. Most servers will accept it this way, if one is really picky, you should replace the space by "+" because that's the replacement character for a space in URL encoding. Never use quotes except your application explicitly can handle that, in any case, it's outside the standard.