Solved

Using POST with HTTP_Request does not work

Posted on 2007-12-03
11
301 Views
Last Modified: 2008-05-02
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
Comment
Question by:shang3000
  • 5
  • 4
  • 2
11 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20394838
$r = new HTTP_Request($url);

Are you sure you mean to post to the root (index.php) of the web server?
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20394858
two other possibilities
1. include from HTTP/
include("HTTP/Request.php");

2. maybe authentication is required
$req->setBasicAuth("MY_USERNAME", "MY_PASSWORD");
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 20394860
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 20394872
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
 

Author Comment

by:shang3000
ID: 20394952
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
ID: 20395134
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
 

Author Comment

by:shang3000
ID: 20456473
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 20456535
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
 

Author Comment

by:shang3000
ID: 20456633
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
 
LVL 40

Expert Comment

by:RQuadling
ID: 20456656
I would close this question first as we are wandering off topic considerably.
0
 

Author Comment

by:shang3000
ID: 20456922
ok and thank you very much any way
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now