Newsgroup: it.comp.www.php
Titolo: postare dati su una pagina web (metodo POST)

<?php
 
$uri = '/insert_data.php';
$parameters = array('test' => 'abc');
 
if (!($sock = fsockopen($uri, 80))) die ("Errore connessione\n");
 
 
fputs($sock, post::buildContent($uri, $parameters));
 
$out = '';
while ( ! feof($sock) ) $out .= fgets($sock);
 
fclose($sock);
 
function buildContent($uri, $parameters = array()) {
 
     $query = buildQuery($parameters);
 
     $content =
         "POST $uri HTTP/1.1\r\n".
         "Host: $uri\r\n".
         "Content-Type: application/x-www-form-urlencoded\r\n".
         "Content-Length: " . strlen($query) . "\r\n".
         "Connection: close\r\n".
         "\r\n".
         "$query\r\n"
     ;
 
     return $content;
 
}
 
function buildQuery($parameters = array()) {
 
     if ( ! is_array($parameters) ) {
         $parameters = array($parameters);
     }
 
     $records = array();
 
     foreach ($parameters as $key => $value) {
         array_push(
             $records,
             "$key=$value"
         );
     }
 
     return implode('&', $records);
}
 
 
?>
 
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: 
System error in /tmp/post.php on line 6
Warning: fsockopen(): unable to connect to /insert_data.php:80 
(php_network_getaddresses: getaddrinfo failed: System error) in 
/tmp/post.php on line 6
Errore connessione
 
Perchè?

 Perchè?
 
Forse la porta 80 e' gia' impegnata? Magari da apache?
 
Ciao.
 
-- 
Pubblicita' regresso: 
http://www.ferrero.org
 
** Per scrivermi in mail, sostituire nutella con ferrero...
** To contact me by email, change nutella to ferrero...
 

 Perchè?
 
Perché devi dargli l'hostname (o l'IP), non il path.
 
Hai valutato di usare un framework? Sia Zend 1 che symfony (gli altri non 
li conosco) hanno ottime classi per fare chiamate HTTP, che ti astraggono 
tutti i dettagli di basso livello, compreso l'encoding dei dati.
 
Bye.


$uri = '
http://tmp.local/insert_data.php
';
if (!($sock = fsockopen($uri, 80))) die ("Errore connessione\n");
 
 
 
warning: fsockopen(): unable to connect to 
http://tmp.local/insert_data.php:80
 (Unable to find the socket transport 
&quot;http&quot; - did you forget to enable it when you configured PHP?) 
in /tmp/post.php on line 4
 

 warning: fsockopen(): unable to connect to
 
http://php.net/manual/en/function.fsockopen.php
 
 
Stai lavorando coi socket (livello 3/4 dello stack ISO/OSI), non con http 
e html (livello 6/7).
 
Bye.


<?php
 
$path = dirname($_SERVER['SCRIPT_NAME']) . '/insert_data.php';
 
// senza protocollo
fsockopen("tmp.local$path", 80);
 
// senza protocollo e senza nome-server
fsockopen("$path", 80);
 
?>
 
 
( ! ) Warning: fsockopen(): php_network_getaddresses: getaddrinfo 
failed: System error in 
/mnt/hd2-p2/pending/_repository/public/web/php/esperimenti/post.php on 
line 6
 
( ! ) Warning: fsockopen(): unable to connect to 
tmp.local/php/esperimenti/insert_data.php:80 (php_network_getaddresses: 
getaddrinfo failed: System error) in 
/mnt/hd2-p2/pending/_repository/public/web/php/esperimenti/post.php on 
line 6
 
( ! ) Warning: fsockopen(): php_network_getaddresses: getaddrinfo 
failed: System error in 
/mnt/hd2-p2/pending/_repository/public/web/php/esperimenti/post.php on 
line 9
 
( ! ) Warning: fsockopen(): unable to connect to 
/php/esperimenti/insert_data.php:80 (php_network_getaddresses: 
getaddrinfo failed: System error) in 
/mnt/hd2-p2/pending/_repository/public/web/php/esperimenti/post.php on 
line 9
 

 fsockopen("tmp.local$path", 80);
 
forse ho capito, devo solo specificare il nome del server: tmp.local