TCPclient problem with my code

Hi,

I am trying to replace the http client library because I saw that my Photon supports this native.
This is my code, the Photon connects to the server but then nothing happens. I am trying to post data to InfluxDB, the string I would like to send is the same as before. So I assume my http header is not correct:

bool sendInflux(String payload) {
    client.connect(INFLUXDB_HOST,       INFLUXDB_PORT);
    if(client.connected())
    {
        Particle.publish("connected");
    }
    
    client.println("POST /write?db=" + String(INFLUXDB_DB) + " HTTP/1.1");
    client.println("Host: " + String(INFLUXDB_HOST));
    client.println("User-Agent: Photon/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/json");
    client.println(payload.length());
    client.println();
    client.print(payload);
    client.println();             
    client.stop();
}

I would be very grateful if you could tell me what I am doing wrong.

I think one of the lines should be:

 client.printlnf(“Content-Length: %d”, payload.length());
1 Like

Thank you very much! That was to problem, now it works perfectly! :smile:

1 Like