make http request to another url...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deostroll
Forum Newbie
Posts: 7
Joined: Sat Dec 12, 2009 8:10 am

make http request to another url...

Post 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...
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: make http request to another url...

Post by Darhazer »

Did you tried with cURL?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: make http request to another url...

Post 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?
deostroll
Forum Newbie
Posts: 7
Joined: Sat Dec 12, 2009 8:10 am

Re: make http request to another url...

Post 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?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: make http request to another url...

Post 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
deostroll
Forum Newbie
Posts: 7
Joined: Sat Dec 12, 2009 8:10 am

Re: make http request to another url...

Post by deostroll »

okay the issue is resolved...it is with the way the java application is actually supposed to execute...
Post Reply