Page 1 of 1
[SOLVED] - Sending POST auto returns header Location URL
Posted: Tue Jul 26, 2005 4:36 am
by anjanesh
Hi
I have a function that simulates HTTP POST.
Code: Select all
echo httpPOST("www.somewhere.com", "/somepage.php", $Data)
It works but but I keep getting the result
Code: Select all
HTTP/1.1 302 Found
Date: Tue, 26 Jul 2005 09:34:34 GMT
Server: Apache
Location: http://www.somewhere.com/someredirect.html?data=somedata
Content-Type: text/html; charset=iso-8859-1 X-Cache: MISS from www.somewhere.com
Connection: close
Found
The document has moved here.
I thought header was taken care by Apache - how do I get this to work correctly ? Like as if a user has manually posted the data.
Thanks
Posted: Tue Jul 26, 2005 6:26 am
by onion2k
Looks like it's working fine to me. The page you're requesting is returning an HTTP 1.1 302 code.. That means the page has moved permanently. You need to follow the link in the header to where the page now resides and get it from there instead.
If you were using the CURL library it would do all that for you.
Posted: Tue Jul 26, 2005 6:49 am
by anjanesh
I tried using CURL too.
Code: Select all
function httpPOST_Curl($Host, $Path, $Data)
{
$handle = curl_init();
curl_setopt ($handle, CURLOPT_URL, $Host."/".$Path);
curl_setopt ($handle, CURLOPT_POST, TRUE);
curl_setopt ($handle, CURLOPT_POST, TRUE);
curl_setopt ($handle, CURLOPT_POSTFIELDS, $Data);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
$file_contents = curl_exec($handle);
curl_close($handle);
return $file_contents;
}
Gives :
Code: Select all
Found
The document has moved here.
But not redirecting !
Posted: Tue Jul 26, 2005 6:55 am
by timvw
You could try
http://www.lastcraft.com/browser_documentation.php which can be configured to follow redirections...
Posted: Tue Jul 26, 2005 7:00 am
by onion2k
anjanesh wrote:I tried using CURL too.
Code: Select all
function httpPOST_Curl($Host, $Path, $Data)
{
$handle = curl_init();
curl_setopt ($handle, CURLOPT_URL, $Host."/".$Path);
curl_setopt ($handle, CURLOPT_POST, TRUE);
curl_setopt ($handle, CURLOPT_POST, TRUE);
curl_setopt ($handle, CURLOPT_POSTFIELDS, $Data);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
$file_contents = curl_exec($handle);
curl_close($handle);
return $file_contents;
}
Gives :
Code: Select all
Found
The document has moved here.
But not redirecting !
You didn't set the CURLOPT_FOLLOWLOCATION option. Which makes it follow (some) redirections.
Posted: Tue Jul 26, 2005 7:04 am
by anjanesh
onion2k wrote:
You didn't set the CURLOPT_FOLLOWLOCATION option. Which makes it follow (some) redirections.
Thanks !
And Thanks tim for sharing the new method.