Solved

Using POST with HTTP_Request does not work

Posted on 2007-12-03
11
303 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

914 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

20 Experts available now in Live!

Get 1:1 Help Now