Problema http POST con request da programma esterno
Salve,
spero sia questa la sezione giusta.
Sono due giorni che tento di fare una richiesta http POST da un software eseguito sul mio PC.
La richiesta è formattata in questo modo:
Codice:
POST /inserisci_coord.php HTTP/1.0\r\nHost: despanet.altervista.org\r\n\User-Agent: Arduino\r\nContent-Type: application/x-www-form-urlencoded" \
"\r\nContent-Lenght: 20\r\n\r\nlat=prova&long=prova\r\n"
Il codice della pagina è questo:
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>senza nome</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 1.22" />
</head>
<body>
<?php
//CONFIGURAZIONE CONNESSIONE MYSQL
$_CONFIG['host'] = "localhost";
$_CONFIG['user'] = "*******";
$_CONFIG['pass'] = "*******";
$_CONFIG['dbname'] = "*******";
//CONNESSIONE
mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die('Impossibile stabilire una connessione');
mysql_select_db($_CONFIG['dbname']);
?>
<?php
if(strlen($_POST["lat"])){
$query_ins = mysql_query("INSERT INTO traccia_coordinate (lat, lon) VALUES ('".$_POST['lat']."', '".$_POST['long']."')");
echo $_POST['lat'];
}else{
$query_ins = mysql_query("INSERT INTO traccia_coordinate (lat, lon) VALUES ('no', 'no')");
echo "non va";
}
?>
</body>
</html>
Il codice nella pagina è corretto. Ho creato un'altra pagina con un form e quando faccio submit inserisce correttamente quello che scrivo nelle caselle del form nel database.
Quando eseguo la richiesta dal mio software la pagina viene raggiunta correttamente ma non vengono inviate o lette le variabili, il server mi restituisce questo:
Codice:
HTTP/1.1 200 OK
Date: Sun, 10 Feb 2013 14:46:11 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 372
Connection: close
Content-Type: text/html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>senza nome</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 1.22" />
</head>
<body>
non va</body>
</html>
C'è qualcosa di sbagliato nel codice della mia richiesta?
Ho provato sia in C che in Python e con vari tutorial e reference su internet e ottengo sempre lo stesso risultato.
Grazie per l'attenzione
Saluti
Fabio