1

i am trying to create server side page in php on which i have to get response from some website through http request. i recieved the error HttpRequest not found. trying to fix this error i was able to find the php_http.dll file for http requests.. i have added it in php extention folder /ext and now i can see the it in the extention list too. but the problem is i am still having the same error... now what i understand is that may be php_http file version is older.. i have php 5.4.16 32bit and the maximum version dll file i can find is 5.3 where do i find compatable verson. or do tell me if i am doing something wrong already....

$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_POST);

this is the line of code i am strugling to remove error from

Syed Naeem
  • 681
  • 8
  • 17

2 Answers2

1

Use the cURL in php

<?php
// A very simple PHP example that sends a HTTP POST to a remote site
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://example.com/feed.rss");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"postvar1=value1&postvar2=value2");

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

// further processing ....
if ($server_output == "OK") { ... } else { ... }

?>

for more see this PHP Difference between Curl and HttpRequest

Community
  • 1
  • 1
sandip
  • 3,279
  • 5
  • 31
  • 54
  • i tried your approach its giving error of call to undefined function curl_init() – Syed Naeem Mar 26 '14 at 07:32
  • Yes you have to enable the curl by default it not enabled see this http://stackoverflow.com/questions/1347146/how-to-enable-curl-in-php-xampp or if you are using wamp, click on wamp icon on the task bar=> then click on PHP =>php extensions=> php_curl – sandip Mar 26 '14 at 07:44
  • i am having another problem now... change this address to youtube.com instead of example.com in the end i am getting in the else part i have pronted serveroutput value there and its seems to have nothing.. its blank. should that be suppose to be happning? – Syed Naeem Mar 26 '14 at 08:17
  • Thats because youtube is not allowing you to make that request, code is fine – sandip Mar 26 '14 at 09:02
0

I would not use HttpRequest for this. I would simply use curl_init(). However, you need to ensure you have php-curl library installed in your machine.

msound
  • 445
  • 3
  • 7
  • looks like i dont have that library u talked about... how can i have that library installed – Syed Naeem Mar 26 '14 at 07:30
  • In case of Ubuntu or a Debian based linux, I would do **sudo apt-get install php5-curl** . In case of using Windows, please see [this](http://stackoverflow.com/a/14736235/3461549) – msound Mar 26 '14 at 07:35