rest post request

Hi!

Can anyone help me out with this code, I can't send it as a string.
I get a "cannot convert 'string to 'init' in initialization" error

the highlighted area is "int httpCode = restpost;"

String restpost = String("{"type":normal,"earliest":2017-01-01T12:00:00,"latest":2100-01-01T12:00:00,"priority":0,"robot_id":0,"mission_id":dc08d14d-3d77-11ea-817c-f44d3061dc08,"creator_id":1}");

void loop(){

while (!(httpCode == 200)){

WiFiClient client;

HTTPClient http;

http.begin(client, "http://192.168.1.27/api/v1.0.0/orders");

http.addHeader("Content-Type", "application/json");
Serial.println("[HTTP] Posting order...\n");

int httpCode = restpost;

String response =http.getString();

Serial.print("StatusCode: ");
Serial.println(httpCode);
Serial.print("Response: ");
Serial.println(response);
delay(500);
}
}

Best regards
Term

and what HttpClient library is it?

Juraj:
and what HttpClient library is it?

Hi

it is this one:

#include <ESP8266HTTPClient.h>

you drifted a little away from the examples

int httpCode = http.POST("{"hello":"world"}");

String restpost = String ("{"type":"normal","earliest":"2017-01-01T12:00:00","latest":"2100-01-01T12:00:00","priority":"0","robot_id":"0","mission_id":"dc08d14d-3d77-11ea-817c-f44d3061dc08","creator_id":"1"}");

void loop(){

while (!(httpCode == 200)){

WiFiClient client;

HTTPClient http;

http.begin(client, "http://192.168.1.27/api/v1.0.0/orders");

http.addHeader("Content-Type", "application/json");
Serial.println("[HTTP] Posting order...\n");

int httpCode = http.POST restpost;

String response =http.getString();

Serial.print("StatusCode: ");
Serial.println(httpCode);
Serial.print("Response: ");
Serial.println(response);
delay(500);
}
}

Best regards
Term

Juraj:
you drifted a little away from the examples

int httpCode = http.POST("{"hello":"world"}");

aah year post were missing, I now chanced it to this, but now get this error:
cannot resolve overloaded function 'POST' based on conversion to type 'int'

String restpost = String ("{"type":"normal","earliest":"2017-01-01T12:00:00","latest":"2100-01-01T12:00:00","priority":"0","robot_id":"0","mission_id":"dc08d14d-3d77-11ea-817c-f44d3061dc08","creator_id":"1"}");

void loop(){

while (!(httpCode == 200)){

WiFiClient client;

HTTPClient http;

http.begin(client, "http://192.168.1.27/api/v1.0.0/orders");

http.addHeader("Content-Type", "application/json");
Serial.println("[HTTP] Posting order...\n");

int httpCode = http.POST restpost;

String response =http.getString();

Serial.print("StatusCode: ");
Serial.println(httpCode);
Serial.print("Response: ");
Serial.println(response);
delay(500);
}
}

I found the last error:

int httpCode = http.POST (restpost);

So it is now working, thanks you very much for your help :slight_smile:

Best Regards
Term