WiFi client connect works with IP but not URL

Hello everyone:

I'm trying to conect my nodemcu to my web server, but this only works when I use my IP adress. I have a dynamic IP adress, therefore i use noip to create a host URL.

Here is my code

#include <ESP8266WiFi.h>
#include <MCP3008.h>
#include <OneWire.h>
#include <DallasTemperature.h>



// ADC
#define CS_PIN 15
#define CLOCK_PIN 14
#define MOSI_PIN 13
#define MISO_PIN 12
MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);


//ID
const byte ID=5;


IPAddress ip(192, 168, 0, 100);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
const char* ssid = "";
const char* password = "";

char host[] = "jimharperr.ddns.net";
String url = "http://jimharperr.ddns.net/index2.php";
const int t_dormido = 30; // Tiempo dormido (en segundos):

//Variables sensor temperatura
#define ONE_WIRE_BUS D4
OneWire oneWire(ONE_WIRE_BUS);  
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;
byte temperatura = 0;
byte humedad = 0;

byte val=0;
byte val2=0;

//Sampling pin
byte sen_vcc = 5;
   

void setup() {
  Serial.begin(115200);
  delay(10);


  
  // Sensor config
  pinMode(sen_vcc,OUTPUT);
  digitalWrite(sen_vcc, HIGH);
  sensors.begin();
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  sensors.setResolution(insideThermometer, 9);

  
  //Wifi
  Serial.print("Connecting to ");
  WiFi.config(ip,  gateway, subnet);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  delay(10);
  Serial.println(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
}


void loop() {
  Serial.print("connecting to ");
  Serial.println(host);
  
  // Creating WIFICLIENT 
  WiFiClient client;
  const int httpPort = 80;

  
   int res = client.connect(host,httpPort);

  Serial.println(res);

  if (res==1) { 
    Serial.println("connected");
  } 
  else { 
    Serial.println("failure! :-(") ;
    Serial.println("connection failed");
    return;
  }


  
  sensors.requestTemperatures();
  float temperatura = sensors.getTempC(insideThermometer);


  Serial.print("Temp:");
  Serial.print(temperatura);
  Serial.print("      Hum:");
  Serial.print(humedad);
    
  int val = adc.readADC(0);
  int val2 = adc.readADC(1);
  int val3 = adc.readADC(2);
  
  Serial.print("      values: ");
  Serial.print(val);
  Serial.print(" , ");
  Serial.print(val2);
  Serial.print(" , ");
  Serial.println(val3);


  
  //Sending information
  String data = String("Ubicacion=")+ID+ String("&Temperatura=") + temperatura + S 
  String("&Humedad=") + humedad+ String("&Humsuelo=") + val+ String("&Humsuelo2=") + val2+ 
  String("&Batt=") + val3;
  client.print(String("POST ") + url + " HTTP/1.0\r\n" +
               "Host: " + host + "\r\n" +
               "Accept: *" + "/" + "*\r\n" +
               "Content-Length: " + data.length() + "\r\n" +
               "Content-Type: application/x-www-form-urlencoded\r\n" +
               "\r\n" + data);


  //fin Lectura de sensores
  digitalWrite(sen_vcc, LOW);
  Serial.println("closing connection");
  //Inicio modo bajo consumo
  ESP.deepSleep(t_dormido * 1000000);
  delay(100);
}

Thanks in advace for your help
Regards

Do you have a question that we could help you with? (I didn't see any question marks in your post.)

Thanks for posting your code correctly with code tags. It would be even better if you could click Tools-->Auto Format before you post next time.

Please expand on your explanation of the setup. Where is the server you refer to?