Sending SOAP requests to server

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 ///////////
}

Thanks in advance,

Steven.

client.println("Content-Length:3000");

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.

Hi Pylon, many thanks for your response. This has been giving me a headache for some time now so I'm glad it looks like I know what I'm doing wrong.

So should my code be the following?:

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:57");
        client.println("zonename=ZONE 1&ctxid=CTX001&calltype=EMERGENCY&cstatus=1");
        client.println();

        client.stop();
      }
      else {
        // if you didn't get a connection to the server:
        Serial.println("connection failed");
      }
    }

Thanks again!

        client.println("zonename=ZONE 1&ctxid=CTX001&calltype=EMERGENCY&cstatus=1");

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.

So you're saying that I shouldn't use quotes when sending the vairables? I've tried the other suggestions but I still can't get it to work.

So you're saying that I shouldn't use quotes when sending the vairables? I've tried the other suggestions but I still can't get it to work.

You need the quotes in the code to quote the string constant but not inside the string.

Post your current code.

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:57");
        client.println(zonename=ZONE 1&ctxid=CTX001&calltype=EMERGENCY&cstatus=1);
        client.println();

        client.stop();
      }
      else {
        // if you didn't get a connection to the server:
        Serial.println("connection failed");
      }
    }

You forgot the empty line to end the header:

if (client.connect(serverIP, 80)) {
        Serial.println("EMERGENCY BUTTON PRESSED");
        
        client.println("POST /ClarocallWebServices.asmx/AddCall HTTP/1.0");
        client.println("Host: localhost");
        client.println("Content-Type: application/x-www-form-urlencoded");
        client.println("Content-Length:57");
        client.println();
        client.println(zonename=ZONE 1&ctxid=CTX001&calltype=EMERGENCY&cstatus=1);
        client.println();

        client.stop();
      }
      else {
        // if you didn't get a connection to the server:
        Serial.println("connection failed");
      }
    }

Edit: And use HTTP/1.0, otherwise you might have to add some more header fields like "Connection: close".

OMG! Pylon, thank you so much, I've now got it working! I've been trying to get this working for months!!!