Page 1 of 1

make http request to another url...

Posted: Sat Dec 12, 2009 8:19 am
by deostroll
hi,

totally new to php. Need to know how to download a web page via php, and display the response onto the screen. I've tried the following thread, but it didn't work...

viewtopic.php?f=1&t=104054&p=556715

Here is my php code:

Code: Select all

<?php 
/*
$handle = fopen("http://www.example.com","r");
$txt = fread($handle, "15");
echo $txt;
fclose($handle);
*/
#$response = http_get("http://www.example.com/", array("timeout"=>1), $info);
#$response = http_request(0,"www.example.com");
//print_r($info);
//print_r($response);
//echo $response;
#echo "this is the end";
echo "hello world"
echo 'test';
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
echo 'test';
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
try 
{
    echo $r->send()->getBody();
} 
catch (HttpException $ex) { echo $ex; }
?>
 
Basically tried everything in there...Running php of LAMP...

Re: make http request to another url...

Posted: Sun Dec 13, 2009 3:29 pm
by Darhazer
Did you tried with cURL?

Re: make http request to another url...

Posted: Sun Dec 13, 2009 3:38 pm
by greyhoundcode
I assume you've tried a simple:

Code: Select all

echo file_get_contents('http://www.yahoo.com');
And if that does not work, are you able to adjust server settings etc so that it would work?

Re: make http request to another url...

Posted: Mon Dec 14, 2009 6:31 am
by deostroll
okay, the file_get_contents() seems to do the job. However we have a local java based app running on the web server. It accepts a url like this:
http://localhost:8081/?language=en&text ... 0an%20test

you'll most probably see this in the browser appearing without the url escapes like this:
http://localhost:8081/?language=en&text=this is an test

calling the function with this url does not fetch the result...why is this so?

Re: make http request to another url...

Posted: Mon Dec 14, 2009 9:26 am
by greyhoundcode
Does the Java app work as expected when called directly? What if you place the Java filename inside the URL, like:

http://localhost:8081/myJavaApp.jsp?language=en&text=this%20is%20an%20test

Re: make http request to another url...

Posted: Mon Dec 14, 2009 2:51 pm
by deostroll
okay the issue is resolved...it is with the way the java application is actually supposed to execute...