Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2007, 09:12 AM
Registered User
 
Join Date: Mar 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTP POST Client/Server

Hi all,

Well i am trying to sent a small xml message via http post method to a specified server.
I have managed to connect to that server but i haven't manage to upload my xml data.
My code looks like:

$fp = fsockopen($host,80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
   $out = "GET /HTTP/1.1\r\n";
   $out .= "Host: $host\r\n";
   $out .= "Connection: Close\r\n\r\n";

  fwrite($fp,$out);
 while (!feof($fp)) {
       echo fgets($fp, 128);
   }

   echo "connected<br/>";

   fclose($fp);
}


Well this script shows me that i am connected but the right thing is to sent the xml file with my username and pwd to connect to that server.

Can anyone help me please?

Thank you.

thanks
 
Old March 22nd, 2007, 07:38 AM
Authorized User
 
Join Date: Mar 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

http://www.jmarshall.com/easy/http/#postmethod
we use the post method
Content-Type would be text/xml

Code:
$xml = [dump xml text in this var]
....

$out  = "POST /HTTP/1.1\r\n";
$out .= "From: $username\r\n";
$out .= "User-Agent: $useragent\r\n";
$out .= "Content-Type: text/html\r\n";
$out .= "Content-Length: " . strlen($xml) . "\r\n\r\n";
$out .= $xml . "\r\n";
$out .= "Connection: Close\r\n\r\n";

....
I haven't tested it myself, so you're bound to need to tinker with the idea
Hope this helps






Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP post silver_scar C# 2005 0 July 31st, 2006 09:52 AM
HTTP POST/GET d_alchemist JSP Basics 1 April 24th, 2006 09:18 AM
XML HTTP Post acdsky Servlets 2 June 2nd, 2005 10:59 AM
HTTP-POST with C# jcascio ASP.NET 1.0 and 1.1 Professional 3 April 12th, 2004 01:15 PM
HTTP Post .Net sjlsysprg1 Pro VB.NET 2002/2003 5 June 26th, 2003 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.