It is currently Thu Mar 28, 2024 12:01 pm


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: local box POSTing to my freehostia website?
PostPosted: Thu Jun 11, 2009 1:29 am 
Newbie
Newbie

Joined: Tue Jun 02, 2009 10:00 pm
Posts: 3
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);

?>



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ]  Moderators: Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Hosting | Domains | Servers | Extras | Order | Support | Contacts | FreeHostia © 2011