mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merged revisions 48902 via svnmerge from
svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r48902 | ischommer | 2008-01-31 16:29:42 +1300 (Thu, 31 Jan 2008) | 1 line added documentation, using $data as array ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52406 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7ae4a30885
commit
15b3fb02b4
@ -231,46 +231,36 @@ class HTTP {
|
||||
return $response;
|
||||
}
|
||||
|
||||
static function sendPostRequest( $host, $path, $data, $name, $query = '', $port = 80 ) {
|
||||
/**
|
||||
* Send a HTTP POST request through fsockopen().
|
||||
*
|
||||
* @param string $host Absolute URI without path, e.g. http://silverstripe.com
|
||||
* @param string $path Path with leading slash
|
||||
* @param array|string $data Payload for the request
|
||||
* @param string $name Parametername for the payload (only if passed as a string)
|
||||
* @param string $query
|
||||
* @param string $port
|
||||
* @return string Raw HTTP-result including headers
|
||||
*/
|
||||
static function sendPostRequest($host, $path, $data, $name = null, $query = '', $port = 80) {
|
||||
$socket = fsockopen($host, $port, $errno, $error);
|
||||
|
||||
$socket = fsockopen( $host, $port, $errno, $error );
|
||||
|
||||
if( !$socket )
|
||||
if(!$socket)
|
||||
return $error;
|
||||
|
||||
if( self::$userName && self::$password )
|
||||
$auth = "Authorization: Basic " . base64_encode( self::$userName . ':' . self::$password ) . "\r\n";
|
||||
if(self::$userName && self::$password)
|
||||
$auth = "Authorization: Basic " . base64_encode(self::$userName . ':' . self::$password) . "\r\n";
|
||||
|
||||
if( $query )
|
||||
if($query)
|
||||
$query = '?' . $query;
|
||||
|
||||
$data = urlencode( $data );
|
||||
$data = $name . '=' . $data;
|
||||
$length = strlen( $data );
|
||||
|
||||
$request = "POST {$path}{$query} HTTP/1.1\r\nHost: $host\r\n{$auth}Content-Type: application/x-www-form-urlencoded\r\nContent-Length: $length\r\n\r\n";
|
||||
|
||||
$request .= $data . "\r\n\r\n";
|
||||
|
||||
fwrite( $socket, $request );
|
||||
$response = stream_get_contents( $socket );
|
||||
|
||||
/*if( $query )
|
||||
$query = '?' . $query;
|
||||
|
||||
$vars['synchronise'] = $data;
|
||||
|
||||
$curl = curl_init('http://' . $host . $path );
|
||||
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, $vars );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_VERBOSE, true );
|
||||
curl_setopt( $curl, CURLOPT_USERPWD, self::$userName . ':' . self::$password);
|
||||
|
||||
$response = curl_exec( $curl );
|
||||
curl_close( $curl );*/
|
||||
$dataStr = (is_array($data)) ? http_build_query($data) : $name . '=' . urlencode($data);
|
||||
$request = "POST {$path}{$query} HTTP/1.1\r\nHost: $host\r\n{$auth}Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($dataStr) . "\r\n\r\n";
|
||||
$request .= $dataStr . "\r\n\r\n";
|
||||
|
||||
fwrite($socket, $request);
|
||||
$response = stream_get_contents($socket);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user