Formatting issues with POST Requst C++

253 Views Asked by At

I am making a http POST request to a server with an Arduino board and therefore using C++. I can connect to the WiFi and server, the issue I am running into is that I am not able to send the variable data to this server. I have written what I believe is the same formatting of the string to JS and sent the request that way and it worked, but I cannot figure out how to make it work via C++.

The following is the code

if (client.connect(server, 80)) {
Serial.println("connected to server");
String myval = "HelloWorld";

// Make a HTTP request:
String body = ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n<soap:Body>\r\n<DataIn xmlns=\"http://www.config.com/\">\r\n<MyVal>" + myval + "</MyVal>\r\n</DataIn>\r\n</soap:Body>\r\n</soap:Envelope>\r\n");

client.print("POST http://eng/wsArduino.asmx HTTP/1.1\r\n");
client.print("Content-Type: text/xml; charset=utf-8\r\n");
client.print("Content-Length: ");
//client.println(myval.length());
//client.print("SOAPAction: \"http://www.config.com/DataIn\"\r\n");
client.println();
client.print(body);
client.println();

Are there any glaring issues, I cannot seem to figure out why this request will not work.

Thank you for any help. This is my first post so please let me know if I have broken any Stackoverflow etiquette.

1

There are 1 best solutions below

0
On

This post should help: http://forum.arduino.cc/index.php?topic=155218.0

Basically, format your params as json before passing them to the client.