Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

Using POST with HTTP_Request does not work

hi all,
I'm trying Using POST with HTTP_Request example but it does not work can you please help me to get it work
thanks in advance
here is the code
best regards
HG
<?php
require 'Request.php';
$url = 'http://hatem.softwarelab.net';
$r = new HTTP_Request($url);
$r->setMethod(HTTP_REQUEST_METHOD_POST);
$r->addPostData('monkey','uncle');
$r->addPostData('rhino','aunt');
$r->sendRequest();
$page = $r->getResponseBody();
print_r($page);
?>

Open in new window

0
shang3000
Asked:
shang3000
  • 5
  • 4
  • 2
1 Solution
 
imitchieCommented:
$r = new HTTP_Request($url);

Are you sure you mean to post to the root (index.php) of the web server?
0
 
imitchieCommented:
two other possibilities
1. include from HTTP/
include("HTTP/Request.php");

2. maybe authentication is required
$req->setBasicAuth("MY_USERNAME", "MY_PASSWORD");
0
 
Richard QuadlingSenior Software DeverloperCommented:
What output do you get?

Here is the first few lines of my output ...



Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\HTTP\Request.php on line 402

Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\HTTP\Request.php on line 720

Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\HTTP\Request.php on line 733

Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\HTTP\Request.php on line 778

Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\PEAR.php on line 569

Strict Standards: Assigning the return value of new by reference is deprecated in C:\PEAR\pear\PEAR.php on line 572

Strict Standards: Redefining already defined constructor for class Net_URL in C:\PEAR\pear\Net\URL.php on line 124

Strict Standards: is_a(): Deprecated. Please use the instanceof operator in C:\PEAR\pear\HTTP\Request.php on line 678

Strict Standards: Non-static method PEAR::getStaticProperty() should not be called statically, assuming $this from incompatible context in C:\PEAR\pear\HTTP\Request.php on line 708

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PEAR\pear\HTTP\Request.php on line 723

Strict Standards: is_a(): Deprecated. Please use the instanceof operator in C:\PEAR\pear\PEAR.php on line 281

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PEAR\pear\HTTP\Request.php on line 725

Strict Standards: is_a(): Deprecated. Please use the instanceof operator in C:\PEAR\pear\PEAR.php on line 281

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PEAR\pear\HTTP\Request.php on line 755

Strict Standards: is_a(): Deprecated. Please use the instanceof operator in C:\PEAR\pear\PEAR.php on line 281
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1" />
<META name=ProgId content=FrontPage.Editor.Document />
<TITLE>Cv</TITLE>
<STYLE>


So, ignoring the errors PEAR has on PHP5 with E_STRICT, I am getting output.


What is the handler for the posted data? The URL you are using is going to load the default page. Now that MAY be something.php, but if it is index.html, then I doubt there is anything behind it to process the posted data.

Richard.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richard QuadlingSenior Software DeverloperCommented:
require_once 'HTTP/request.php';

is the correct thing to use if your include_path has /pear/pear in it (I'm on windows, so mine has C:\PEAR\pear)
0
 
shang3000Author Commented:
hi all,
thanks for reply,

imitchie,
>>>Are you sure you mean to post to the root (index.php) of the web server?
its a static page index.html

>>>2. maybe authentication is required
>>>$req->setBasicAuth("MY_USERNAME", "MY_PASSWORD");
it's not secured it's an html file

RQuadling,
>>>require_once 'HTTP/request.php';
I tried it but no good
also I got no output at all, I'm behined proxy server eg 192.168.0.222
not sure if this is the problem
0
 
Richard QuadlingSenior Software DeverloperCommented:
Aha! Does ...

<?php
echo file_get_contents(''http://hatem.softwarelab.net');
?>

output anything?

If not (and I think this may be your issue), you need to get PHP to know about the proxy server dealing with your setup.

Setting your default gateway to the proxy server could be enough.

So, POST isn't the issue.

Any HTTP activity is the issue.

It's a pity the question can't be changed.

You could try adding the following code to the top of your script or add it to your auto_prepend_file script (if you have one).

I've no idea if this affects pear, but if you wanted to just get the page you could now use file_get_contents() as detailed above.


<?php
$r_default_context = stream_context_get_default
	(
	array
		(
		'http' => array
			( // All HTTP requests are passed through a proxy server.
			'proxy' => 'tcp://192.168.0.222:80', // Make sure IP and port are correct!!!
			'request_fulluri' => True,
			),
		)
	);
 
// Though we said system wide, some extensions need a little coaxing.
libxml_set_streams_context($r_default_context);
?>

Open in new window

0
 
shang3000Author Commented:
hi RQuadling,
you are right and it worked but a small problem there is an image in that page I'm querying but it does not appear at all do you have a solution for this issue ? i hope you have

best regards
HG
0
 
Richard QuadlingSenior Software DeverloperCommented:
When you make a request for a web page, you get just the HTML.

The browser then starts to interpret the markup and realises "Aha! An image tag with a src, so let's make another request to get the picture." sort of thing.

So, everything gets called separately.

AJAX based calls require more than just the HTML rendering engine to work. These require Javascript to be working.

So, getting the html, images/css/js files, ajax data, etc, requires a lot of processing.


So, can you describe exactly what you are trying to achieve?

If you are trying to act as a proxy, then when you read the page, you have to convert all the references to the source URLs to your server.

This involves thinking like a browser. Anything a browser can ask for you have to re-direct to your server so it can you can proxy it through the proxy.
0
 
shang3000Author Commented:
I'm trying to have multiple sites that there contents are been maintained from single point so if added an article it's added to all sites and if a one deleted it'd deleted from all sites and so on but I need to store the result in the data base that reflect the the status of all pages

now after your idea I'm interested in acting as a proxy too

>>>If you are trying to act as a proxy, then when you read the page, you have to convert all the >>>references to the source URLs to your server.

can you please help me in that
guide me how to do it
if there is a syntax that woul be great
best regards
HG
0
 
Richard QuadlingSenior Software DeverloperCommented:
I would close this question first as we are wandering off topic considerably.
0
 
shang3000Author Commented:
ok and thank you very much any way
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now