Re: [PHP] fsockopen + fputs
On 16 May 2008, at 00:04, debussy007 wrote: I use fsockopen and fputs to call a distant URL, but I have the following error : The requested URL /registration/test was not found on this server. This is my code: $req = 'username=' . $usr . '&password=' . $pass . '&date_of_birth=' . $year . "-" . $month . "-" . $day . '&email=' . $email . '&country=' . $country; You should be using urlencode on these variables, otherwise you could end up truncating the data. $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } else { $header = "POST /registration/test HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; fputs ($fp, $header . $req); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } However the path www.example.com/registration/test exists By which I assume you mean "it works in a browser". If not, make sure it works in a browser first. so why does it says it cannot find the requested url ? You probably need a Host header to direct the request to the right website. If you're going to be making manual HTTP requests I suggest you use Firebug or similar to examine the requests your browser is making. Even better read the HTTP spec, but I tend to be realistic in my expectations. Alternatively I'd recommend looking at using the Curl extension. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fsockopen + fputs
debussy007 wrote: Hello, I use fsockopen and fputs to call a distant URL, but I have the following error : The requested URL /registration/test was not found on this server. This is my code: $req = 'username=' . $usr . '&password=' . $pass . '&date_of_birth=' . $year . "-" . $month . "-" . $day . '&email=' . $email . '&country=' . $country; $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } else { $header = "POST /registration/test HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; fputs ($fp, $header . $req); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } However the path www.example.com/registration/test exists so why does it says it cannot find the requested url ? Any idea ? Thank you for any help !! try changing to POST /registration/test/ HTTP/1.0\r\n note the trailing slash on test also if that fails try http/1.1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fsockopen + fputs
debussy007 wrote: > However the path www.example.com/registration/test exists > so why does it says it cannot find the requested url ? > > Any idea ? Thank you for any help !! Take a look at the accesslog on www.example.com - that'll tell you what's happening. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fsockopen + fputs
Hello, I use fsockopen and fputs to call a distant URL, but I have the following error : The requested URL /registration/test was not found on this server. This is my code: $req = 'username=' . $usr . '&password=' . $pass . '&date_of_birth=' . $year . "-" . $month . "-" . $day . '&email=' . $email . '&country=' . $country; $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } else { $header = "POST /registration/test HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; fputs ($fp, $header . $req); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } However the path www.example.com/registration/test exists so why does it says it cannot find the requested url ? Any idea ? Thank you for any help !! -- View this message in context: http://www.nabble.com/fsockopen-%2B-fputs-tp17264395p17264395.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php