~tsep-dev/tsep/0.9-beta

« back to all changes in this revision

Viewing changes to branches/symfony/app/vendors/post_to_url.php

  • Committer: geoffreyfishing
  • Date: 2011-01-11 23:46:12 UTC
  • Revision ID: svn-v4:ae0de26e-ed09-4cbe-9a20-e40b4c60ac6c::125
Created a symfony branch for future migration to symfony

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
* POST data to a URL
 
4
 
5
* @author geoffreyfishing
 
6
*
 
7
* The following will be filled automatically by SubVersion!
 
8
* Do not change by hand!
 
9
*  $LastChangedDate: $
 
10
*  $LastChangedBy:  $
 
11
*  $LastChangedRevision: $
 
12
*
 
13
*/
 
14
 
 
15
function do_post_request($url, $data, $optional_headers = null)
 
16
{
 
17
  $params = array('http' => array(
 
18
              'method' => 'POST',
 
19
              'content' => $data
 
20
            ));
 
21
  if ($optional_headers !== null) {
 
22
    $params['http']['header'] = $optional_headers;
 
23
  }
 
24
  $ctx = stream_context_create($params);
 
25
  ob_start();
 
26
        $fp = fopen($url, 'rb', false, $ctx);
 
27
  if (!$fp) {
 
28
    throw new Exception("Problem with $url; ".ob_get_clean());
 
29
  }
 
30
  $response = @stream_get_contents($fp);
 
31
  if ($response === false) {
 
32
    throw new Exception("Problem reading data from $url; ".ob_get_clean());
 
33
  }
 
34
  ob_end_clean();
 
35
  return $response;
 
36
}
 
 
b'\\ No newline at end of file'