Link to home
Start Free TrialLog in
Avatar of shang3000
shang3000

asked on

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

Avatar of imitchie
imitchie
Flag of New Zealand image

$r = new HTTP_Request($url);

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

2. maybe authentication is required
$req->setBasicAuth("MY_USERNAME", "MY_PASSWORD");
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.
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)
Avatar of shang3000
shang3000

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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
I would close this question first as we are wandering off topic considerably.
ok and thank you very much any way