473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

doing an http post

For the benefit of others, I want to show how to do
an HTTP POST request using fsockopen(). I banged my
head against a wall for two days trying to figure
this out. I even went to http://php.net/ to find
out how to do this, but it didn't help because
my mind automagically converted the "Content-Length"
header into "Length."

I even went to http://www.ietf.org/ to find out
the specific protocol for HTTP POSTs, but I didn't
find it there. RFC 2616 (HTTP) does not give the
exact format for POST requests.

Question: Where is the format for POST requests defined?

---------------- send_post.php ---------------
<?php
// file: send_post.php
error_reporting (E_ALL & ~E_NOTICE);
$eol = "\r\n";
$errno = 0;
$errstr = '';
$data = 'username=georg e&password=i81b pz';
$fid = fsockopen('loca lhost', 8080, &$errno, &$errstr, 30);
if ($fid) {
fputs ($fid, "POST /post/show_post.php HTTP/1.1$eol");
fputs ($fid, "HOST: localhost$eol") ;
fputs ($fid, "Connection : close$eol");
fputs ($fid, "Content-Type: application/x-www-form-urlencoded$eol" );

// Use 'Content-Length' NOT 'Length' !
fputs ($fid, 'Content-Length: ' . strlen($data) . $eol);
fputs ($fid, $eol);
fputs ($fid, $data);
fputs ($fid, $eol);
fpassthru($fid) ;
}

?>

------------- show_post.php -----------------
<?php
// file: show_post.php
error_reporting (E_ALL & ~E_NOTICE);

echo "<pre>\n";
echo "------------ POST VARIABLES ----------\n";
print_r($HTTP_P OST_VARS);
echo "------------ SERVER VARIABLES ----------\n";
print_r($HTTP_S ERVER_VARS);
echo "</pre>\n";
?>
Jul 16 '05 #1
4 17115
"Gary Petersen" <ga*******@REMO VE.MEearthlink. INVALID> skrev i en meddelelse
news:pa******** *************** *********@REMOV E.MEearthlink.I NVALID...
For the benefit of others, I want to show how to do
an HTTP POST request using fsockopen(). I banged my
head against a wall for two days trying to figure
this out. I even went to http://php.net/ to find
out how to do this, but it didn't help because
my mind automagically converted the "Content-Length"
header into "Length."

Use curl instead.

---
Rasmus Christian Kaae
www.3kings.dk | www.hestebasen.com
Jul 16 '05 #2
With total disregard for any kind of safety measures "Rasmus
Christian Kaae" <ra**********@3 kings.dk> leapt forth and uttered:
For the benefit of others, I want to show how to do
an HTTP POST request using fsockopen(). I banged my
head against a wall for two days trying to figure
this out. I even went to http://php.net/ to find
out how to do this, but it didn't help because
my mind automagically converted the "Content-Length"
header into "Length."

Use curl instead.


What an amazingly helpful answer.

Try something like this? :

function PostToHost($hos t, $path, $data_to_send) {
$fp = fsockopen($host ,80);
fputs($fp, "POST $path HTTP/1.1\n" );
fputs($fp, "Host: $host\n" );
fputs($fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs($fp, "Content-length: ".strlen($data_ to_send)."\n" );
fputs($fp, "Connection : close\n\n" );
fputs($fp, $data_to_send);
fclose($fp);
}

--
There is no signature.....
Jul 16 '05 #3
Gary Petersen wrote:
Question: Where is the format for POST requests defined?


Try:
www.w3c.org

The RFC in question is RFC2616, which is the HTTP/1.1 specification and
can be found here:
ftp://ftp.isi.edu/in-notes/rfc2616.txt

--
MeerKat

Jul 16 '05 #4
On Sat, 23 Aug 2003 05:38:35 -0500, in message
<Xn************ *************@2 16.196.97.132>, the AI program named "Phil
Roberts" <ph*****@holyfl atnetshit.net> randomly printed:
fputs($fp, "POST $path HTTP/1.1\n" );
fputs($fp, "Host: $host\n" );


I thought that the end of line sequence was
\r\n not just \n.

Jul 16 '05 #5

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

Similar topics

1
13621
by: steven | last post by:
Hallo, I want to post an xml-doc to an URL using PHP. How can I do that ? //$dom is the xml dom which I want to send. $dom=domxml_open_file("example.xml"); Thanks,
0
1259
by: Klem | last post by:
I am doing HTTP post and I am receiving the following error: System.IO.IOException: Unable to write data to the transport connection. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine at System.Net.Sockets.Socket.BeginSend(Byte buffer, Int32 offset, Int32 size, SocketFlags...
3
6874
by: Patrick Fogarty | last post by:
I am programming what is to be a web service client that will use an HTTP-POST to request and retrieve data. The remote server (written in java for what it's worth) requires basic authentication as per RFC 2617 (http://www.faqs.org/rfcs/rfc2617.html). My attempts to authenticate are failing. The server requires the header to be present with...
3
4901
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to one post for every 10 seconds the client start getting error 403 'forbidden' from the webserver after a short period of time. The webserver is IIS....
1
2595
by: Arfeen | last post by:
Hi All, I need help again ..... I have an asp.net web page which I hit using the "HTTP POST" method. My ASP.NET page is a basic hello world example with the following code: private void Page_Load(object sender, System.EventArgs e) {
0
1561
by: jayhunters14 | last post by:
hi i am doing a post via the hyperterminal thru my gprs modem. i am exchanging raw data with a server. i can use GET method but i cannot post a value to my php script.can anyone please help me because i don't have any background in http: i try to issue this command: POST /path HTTP/1.1<crlf> host:www.hostname.com<crlf> content-type:...
6
5094
by: Brybot | last post by:
I am trying to allow HTTP POST file uploads to my web service. Currently I have it working perfectly for a SOAP/XML request reading in a byte using MemoryStream/FileStream but I cannot figure out how to encode a file on a POST to the same web service. The definition requires a base64binary encoded file, which I have tried. The form is also...
3
3600
by: computer_guy | last post by:
Hi Everyone, I run into a problem. I am trying to write an aspx that can dynamically generate an image based on some input parameters. Things are very simple if the size of the parameters is small and I can put them on the URL and pass them in as HTTP GET. In my image generation script I just need to read the parameters and then pump out...
5
3267
by: Thomas Lunsford | last post by:
I have been asked to allow one of our old-school .asp pages to support being used as a web service. Specifically, WSDL was mentioned. I am not an expert on this , but I have done quite a bit of reading, and I understand that I can create a WSDL file that supports HTTP POST and then use WSDL.exe with the proper parameters to generate a web...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.