473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

sending http post requests

i'm trying to send an http post request and see if the server got it
correctly. i'm sending the http post request with this script:

<?
$address = 'domain.tld';
$port = 80;

$proxy = fsockopen("tcp://$address", (int) $port, $errno, $errstr, 1);

$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");
fputs($proxy,"Content-Length: ".strlen($extra)."\r\n\r\n");
fputs($proxy,"$extra\r\n");

while (!feof($proxy))
print fgets($proxy);
fclose($proxy);
?>

test.php's contents are as follows:

<?
print_r($_POST);
?>

this is what i want to see:

Array
(
[extra] => blah
[this] => test
)

this is what i am seeing:

Array
(
)

any ideas as to what i'm doing wrong and how i can fix it? thanks!

Jul 17 '05 #1
2 2748
yawnmoth wrote:
i'm trying to send an http post request and see if the server got it
correctly. i'm sending the http post request with this script:

My script looks almost exactly the same (but works ;). A couple of
suggestions:
<?
$address = 'domain.tld';
$port = 80;

$proxy = fsockopen("tcp://$address", (int) $port, $errno, $errstr, 1);

Timeout seems a bit short - but OK for testing locally. The 'tcp://' was new
to me - according to the manual it's valid. Might be worth trying without.
$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");
** maybe add : "Content-type: application/x-www-form-urlencoded\r\n";
fputs($proxy,"Content-Length: ".strlen($extra)."\r\n\r\n");
fputs($proxy,"$extra\r\n");


literal paste from my script:
$p.="Content-length: $len\n\n";
$p.= "$str\n";
$p.= "\r\n";

It was kind of a long tiime ago I wrote it, and can't recall why the first
two lines didn't get a '\r'.

HTH

C.
Jul 17 '05 #2

Colin McKinnon wrote:
yawnmoth wrote:
$extra = "extra=blah&this=test";

fputs($proxy,"POST /test.php HTTP/1.0\r\n");
fputs($proxy,"Host: $address\r\n");


** maybe add : "Content-type: application/x-www-form-urlencoded\r\n";


That fixed it - thanks! :)

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
1
by: Dhwanil Shah | last post by:
Hi, We have an aspx page designed in VS.NET 2003. Our requirement is that a client (another application), sends HEAD requests to our application with Basic Auth header. Based on security criteria,...
4
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.