Http error code


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.

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.

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