FreeHostia Forums https://forum.freehostia.com/ |
|
local box POSTing to my freehostia website? https://forum.freehostia.com/viewtopic.php?f=7&t=9991 |
Page 1 of 1 |
Author: | jedbee [ Thu Jun 11, 2009 1:29 am ] |
Post subject: | local box POSTing to my freehostia website? |
how can I pass POST data from a local box to my website? I've tried the following code snippets but they do not seem to work: (a page on my freehostia site would go where www.url.com is) Code: <?php do_post_request('http://www.url.com','post data'); function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'post', 'content' => $data )); if ($optional_headers!== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } ?> Code: <?php
$data = "Here is my POST data"; $url = "http://www.url.com"; $opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"User-Agent: My Own Http Client\r\n". "Content-length: " . strlen($data)."\r\n", 'content' => $data ) ); $context = stream_context_create($opts); $fp = fopen($url, 'r', false, $context); fgets($fp); ?> |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |