1

I was trying to connect with server but, I was unable to post the data. I have added the SSL key to connect with server that is happening but HTTPS POST is not. I tried the same method with http, I am able to connect with server in that case.

/* set SSL/TLS certificate */
    client.setCACert(ca_cert);
//////////////////////////////// try to connect to server again and POST the data on the cloud //////////////////////////
  if (!client.connect(host, httpsPort)) {
     Serial.println("Connection failed!");
  } else {
     Serial.println("Connected to server!"); 
     client.println("POST /devices/deviceData HTTP/1.1");
     client.println("Host: api.thi***i.io");
     client.println("cache-control: no-cache");
     client.println("Content-Type: application/json");
     client.println("Authorization: Bearer eyJ0e***");
     client.println("Postman-Token: b1f4e147-8d13-4a27-a1a9-b****");
     client.print("Content-Length: ");
     client.println(PostValue.length());
     client.println();
     client.println(PostValue);
  }
  Serial.print("Waiting for response ");
  while (client.available() == 0) {
     if (millis() - timeout > 50000) {
        Serial.println(">>> Client Timeout !");
        client.stop();
        return;
     }
  }

  Serial.println("Response From Server");
  while(client.available()) { 
     char c = client.read();
     Serial.write(c);       
  }

It should connect from my logic but I am getting server error 400. Can I know, what can be issue here?

  • Still, I am getting the same issue. Bad Response 400 – Mohit Tripathi Dec 16 '18 at 7:19
  • Is there any other method to resolve this issue? – Mohit Tripathi Dec 16 '18 at 7:57
  • I have fixed in my code. But, still I am getting the same issue. – Mohit Tripathi Dec 16 '18 at 8:42
  • I have edited into the question. I have removed client.println() and in my code also. But, still I am getting BAD response from the servre. Is there any space or next line I am missing into the code? – Mohit Tripathi Dec 16 '18 at 14:10
  • 1
    this does not say if you were able to connect to the server .... I was trying to connect with server. But, I was unable to post the data. .... please clarify you post – jsotola Dec 16 '18 at 19:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.