Go Down

Topic: Http error code (Read 42 times) previous topic - next topic


Sep 18, 2019, 10:02 pm Last Edit: Sep 18, 2019, 10:04 pm by ebolisa

The function below sends a string to a database through a php code.

However, when run it, I get an error code but I'm not sure what I'm doing wrong.

Code: [Select]

httpRequestData: api_key=tPmAT5Ab3j7F9&value1=
Error code: -1

If in place of the extIP I use a string like "123", it works fine.

Surely is the ip address which is the cause of the problem.

Any help is appreciated.

Code: [Select]
void db_send() {
  //Check WiFi connection status

  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;

    // Your Domain name with URL path or IP address with path

    // Specify content-type header
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");

    // Prepare your HTTP POST request data
    String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + extIP + "&value2=" + 0 + "&value3=" + 0 + "";
    Serial.print("httpRequestData: ");

    // Send HTTP POST request
    int httpResponseCode = http.POST(httpRequestData);

    if (httpResponseCode > 0) {
      Serial.print("HTTP Response code: ");
    else {
      Serial.print("Error code: ");

    // Free resources
  else {
    Serial.println("WiFi Disconnected");


You may need to encode your URL by replacing special characters (i.e. periods) with certain codes. In your case you would replace the periods with %2E.

URL Encoding Reference
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

Go Up