Error 400 in GET requisition with arduino

Hi!

I`m creating a aplicattion with arduino, and I need to make a GET requisition in my server, and every time I try to do this i get a ERROR 400 BAD REQUEST. So my arduino is reading some data like temperature and humid and send this to my server that has a PHP file that will receive the two variables and put this in a data bank. So when I try to do this in the browser, in my case google chrome, and put this in the URL

XXXXXXXXXXXX/weather/insert_weather.php/?temp=25&humid=40

(Where X is the name of my web site)

The file are put in my data bank normaly, the way I want.

But in arduino I`m using this:

///////////////////////////////

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include "DHT.h"
#define DHTTYPE DHT22

const char* ssid = "XXXXXXXXX";
const char* password = "XXXXXXXXXX";

const int DHTPin = 2;

DHT dht(DHTPin, DHTTYPE);

static char celsiusTemp[7];
static char fahrenheitTemp[7];
static char humidityTemp[7];

const char http_site[] = "XXXXXXXXXXX";
const int http_port = 80;

WiFiClient client;

IPAddress server(xxx,xxx,xxx,xxx);

void setup() {
delay(2000); //Aguarda 2 segundos
Serial.begin(115200);

dht.begin();

Serial.println("NodeMCU - Putting data int DB Using GET");
Serial.print("Trying to connect to: ");
Serial.println(ssid);
Serial.println("Waiting for connection");

WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED ) {
delay(1000);
Serial.print(".");
}
Serial.print("\nWI-FI Connection sucess: ");
Serial.println(ssid);

}

void loop() {

//Read of sensor DHT11
delay(3000);
float humid = dht.readHumidity();
// Read temperature as Celsius (the default)
float temp = dht.readTemperature();

if (isnan(humid) || isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
strcpy(celsiusTemp,"Error");
strcpy(fahrenheitTemp, "Error");
strcpy(humidityTemp, "Error");
return;
}

Serial.println("Puttin data on DB: ");
Serial.print((float)temp);
Serial.print(" *C, ");
Serial.print((float)humid);
Serial.println(" %");

if ( !getPage((float)temp,(float)humid) ) {
Serial.println("GET request failed");
}
}

bool getPage(float temp, float humid)
{
if ( !client.connect(server, http_port) )
{
Serial.println("Error in connection ");

return false;
}
String param = "/?temp=" + String(temp) + "&humid=" + String(humid);
Serial.println(param);
Serial.println("GET /weather/insert_weather.php" + param + " HTTP/1.1\r\n");

client.println("GET /weather/insert_weather.php" + param + " HTTP/1.1\r\n");
// client.println("GET /favicon.ico HTTP/1.1\r\n");
client.println(http_site);
client.println("Connection: close");
client.println();
client.println();

while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
return true;
}

///////////////////////////////

Ive search a lot on internet and couldnt find an anwser to this, please help me!

Some details:
My server is an APACHE
The port that im using is 80, Ive tried using 8080 and 50000, and with both I cant connect Im using a WIFI connection to arduino

What does your serial output look like?

The / between the php and the ? does NOT belong there.

The server is correct, you're sending a bad request.

Let's see the relevant code:

client.println("GET /weather/insert_weather.php" + param + " HTTP/1.1\r\n");
  client.println(http_site);
  client.println("Connection: close");
  client.println();
  client.println();

You are sending a more or less (the '/' in param is not necessary as PaulS stated but doesn't harm usually, but that depends on the server configuration) correct first line. To be noted: you say to follow HTTP version 1.1 and not HTTP version 1.0 which is less complicated. At the end you're sending carriage return and line feed although you use the println() method which also appends this. That results in twice a CR/NL combination or an empty line after the first line. An empty line denotes the end of an HTTP header but you're missing several mandatory header lines if using HTTP/1.1. And then you're sending additional data although the header doesn't say so (because it's already finished). The server has no other chance than to reject your request.

Remove that "\r\n" from that line to fix the first line.
The second line. You're sending the "XXX" which I guess just holds your server name. That doesn't make the complete header line though. So change that to

client.print("Host: ");
client.println(http_site);

The connection-close line is correct. But then you insert two empty lines while the server expects only one. Remove the second one. I guess you get a better response if you change these things.