Hello,
New to PHP and New to the forum here.
Anyway, for my website, I need to make a HTTPRequest to a websiteURL and get the response which will be an XML document (90% of the time).
I looked into the HTTPRequest class but I couldn't get it to work with my code.
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;
This is what I have for my php.ini file....
#Sun Apr 05 14:04:18 IDT 2009
zend_extension=./ZendDebugger.so
extension=php_http.dll
I was told to add extension = php_http.dll to the ini file so I did, but its not working.
As you can see, I have put two "echo 'test';" phrases and the second echo doesn't actually get called so I'm guessing theres something wrong with the
httprequest code (probably not recognizing). I am not familiar with how import/include works with php..... I'm guessing php.ini is doing it ?
Anyway, help will be very much appreciated
Creating a http request via PHP
Moderator: General Moderators
Re: Creating a http request via PHP
Forget that thing - cURL is much easier to use, doesn't require any magic strings or option names, and is more widely used and supported.
Code: Select all
$ch = curl_init("http://www.example.com/form.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"user" => "username",
"pass" => "password"
));
// do you really need cookies for this?
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);Re: Creating a http request via PHP
The HTTPRequest class is actually pretty decent. Certainly easier to use than cURL (cURL is for more advanced usage)
Don't forget to restart your apache service
You have a UNIX and a Windows extension here. Which are you running? if it's Linux, then you need to change .dll to .sozend_extension=./ZendDebugger.so
extension=php_http.dll
Don't forget to restart your apache service
Re: Creating a http request via PHP
Yeah... so I looked into it (after I posted, of course) and it does look rather nice. Not as powerful as cURL but since it can focus on one area in particular it can do it a bit better.pytrin wrote:The HTTPRequest class is actually pretty decent. Certainly easier to use than cURL (cURL is for more advanced usage)
I really need to stop doing things like that... I think it's time for another hiatus from DevNetwork.