Hello everyone,
I am doing a project with an Arduino UNO and an Ethernet Shield, It consists of doing an HTTP POST from a JSON to a Server, I have reviewed my code many times and I still have the same error, the server receives my POST but it tells me that there is a missing parameter.
However I am sending the parameter I have tried many ways that I have seen all over the internet but I still do not get a solution
My Code :
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC CUALQUIERA
byte server[] = {172, 30, 31, 6}; //IP SERVIDOR
byte ip[] = {172, 30, 36, 32}; // IP ARDUINO
EthernetClient client; // DEFINIMOS EL CLIENTE
void setup() {
// INICIO DEL SETUP ################################################################
Serial.begin(9600); // INICIALIZAR MONITOR SERIAL
while(!Serial){
;
} // ESPERAR POR EL MONITOR SERIAL
SPI.begin();
Ethernet.begin(mac, ip); //Conexion Por ip Estatica
Serial.print("My IP : ");
Serial.println(Ethernet.localIP());
delay(500);
if (client.connect(server, 80)) { //comprobar si hay conexion con el cliente
Serial.println("conectado a 172.30.31.6");
}else{
Serial.println("NO HAY CONEXION");
}
char PostData[] = "{\"operation\":\"core/create\",\"class\":\"UserRequest\",\"output_fields\":\"id\",\"comment\":\"loquesea\",\"fields\":{\"org_id\":\"1\",\"title\": \"prueba_hospital\",\"description\":\"prueba\"}}";
if (client) {
client.println("POST /itop/web/webservices/rest.php?version=1.1&json_data= HTTP/1.1");
client.println("Host: 172.30.31.6");
client.println("Authorization: Basic YWRtaW46YWRtaW4="); // User and pass in Base64
client.println("User-Agent: Arduino/1.8.5");
client.println("Content-Type: application/json");
client.print("Content-Lenght: ");
client.println(strlen(PostData));
client.println("Connection: close");
client.println();
client.print(PostData);
Serial.println("Post Realizado");
}else {
Serial.println("No se ha podido hacer el POST");
}
} // FINAL DEL SETUP #########################################################
void loop() { // INICIO DEL LOOP ####################################################################
if(client){
char c = client.read();
Serial.print(c);
}
delay(10);
}
In the first line of the post, I am sending the parameters:
version = 1.1 & json_data =
probe send the json_data down along with the json himself, but it has not worked either
client.println("POST /itop/web/webservices/rest.php?version=1.1&json_data= HTTP/1.1");
Response :
My IP : 172.30.36.32
conectado a 172.30.31.6
Post Realizado
Date: Wed, 02 May 2018 21:12:56 GMT
Server: Apache/2.4.25 (Debian)
Set-Cookie: itop-cccc625803db2ea97734aa176e552d97=oh2ru9fe93p13jvqes0sfek446; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Content-Disposition: inline; filename=""
Content-Length: 58
Connection: close
Content-Type: application/json
{"code":3,"message":"Error: Missing parameter 'json_data"}
Thank you all, I hope you can find the error where I can not find it