Solved

Using POST with HTTP_Request does not work

Posted on 2007-12-03
11
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Richard Quadling
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 40

Expert Comment

by:Richard Quadling
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
 
LVL 40

Accepted Solution

by:
Richard Quadling 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:Richard Quadling
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:Richard Quadling
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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