PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > problem with fsockopen and HTTP GET
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
problem with fsockopen and HTTP GET

Réponse
 
LinkBack Outils de la discussion
Vieux 25/04/2008, 21h16   #1
beau.moore@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut problem with fsockopen and HTTP GET

Hi all,

I need some , I am trying to access a service that binds to the
loopback address on my linux FC8 server. I think PHP functions but I
am unable to get any response back from the fgets() command below.

The service is GoogleDesktop for Linux, I am aware of all of the
restrictions in place to prevent what I am trying to do but I want to
try anyway. It seems to me that my http request should look just like
an http request from Firefox to the Google Desktop Search, so I
thought that I could mimic that request by using fsockopen and fgets.

I captured all of the headers in a request using Live Headers plugin
in Firefox, when I replay the headers with a GET request in Firefox it
works fine.

So my question is "what is wrong with my code below?" I should get an
error message back at least right? fgets returns nothing.

I even tried to do it with another website instead of 127.0.0.1, just
like cnn.com, again fgets returns nothing not even an error.


<?php


$fp = fsockopen("127.0.0.1", 31846 , $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {

$out = "GET /?hl=en_US&src=14&s=4xrcacQv6jHUIsB0GtlFZ2j9QJw HTTP/1.1\r
\n";
$out .= "Host: 127.0.0.1:31846\r\n";
$out .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
1.8.1.3) Gecko/20070320 Firefox/2.0.0.3\r\n";
$out .= "Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n";
$out .= "Accept-Language: en-us,en;q=0.5\r\n";
$out .= "Accept-Encoding: gzip,deflate\r\n";
$out .= "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n";
$out .= "Keep-Alive: 300\r\n";
$out .= "Connection: keep-alive\r\n\r\n";



fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 4096);
}
fclose($fp);
}

?>
  Réponse avec citation
Vieux 25/04/2008, 23h26   #2
Álvaro G. Vicario
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: problem with fsockopen and HTTP GET

*** beau.moore@gmail.com escribió/wrote (Fri, 25 Apr 2008 13:16:30 -0700
(PDT)):
> $out .= "Keep-Alive: 300\r\n";
> $out .= "Connection: keep-alive\r\n\r\n";


Try:

$out .= "Connection: Close\r\n\r\n";

I'm not sure whether it has something to do with your problem but there's
no point in telling the server to keep the connection open if your script
won't handle it. Keep us informed.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor en cubitos: http://www.demogracia.com
--
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h14.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08862 seconds with 10 queries