| 1 |
lars |
1 |
<?PHP
|
|
|
2 |
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +----------------------------------------------------------------------+
|
|
|
4 |
// | PHP Version 4 |
|
|
|
5 |
// +----------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (c) 1997-2002 The PHP Group |
|
|
|
7 |
// +----------------------------------------------------------------------+
|
|
|
8 |
// | This source file is subject to version 2.0 of the PHP license, |
|
|
|
9 |
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
10 |
// | available at through the world-wide-web at |
|
|
|
11 |
// | http://www.php.net/license/2_02.txt. |
|
|
|
12 |
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
13 |
// | obtain it through the world-wide-web, please send a note to |
|
|
|
14 |
// | license@php.net so we can mail you a copy immediately. |
|
|
|
15 |
// +----------------------------------------------------------------------+
|
|
|
16 |
// | Authors: Stephan Schmidt <schst@php.net> |
|
|
|
17 |
// +----------------------------------------------------------------------+
|
|
|
18 |
//
|
|
|
19 |
// $Id: Curl.php,v 1.2 2004/10/29 21:23:06 schst Exp $
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Services/Ebay/Transport/Curl.php
|
|
|
23 |
*
|
|
|
24 |
* Send a request via Curl
|
|
|
25 |
*
|
|
|
26 |
* @package Services_Ebay
|
|
|
27 |
* @author Stephan Schmidt <schst@php.net>
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Services/Ebay/Transport/Curl.php
|
|
|
32 |
*
|
|
|
33 |
* Send a request via Curl
|
|
|
34 |
*
|
|
|
35 |
* @package Services_Ebay
|
|
|
36 |
* @author Stephan Schmidt <schst@php.net>
|
|
|
37 |
*/
|
|
|
38 |
class Services_Ebay_Transport_Curl
|
|
|
39 |
{
|
|
|
40 |
/**
|
|
|
41 |
* send a request
|
|
|
42 |
*
|
|
|
43 |
* @access public
|
|
|
44 |
* @param string uri to send data to
|
|
|
45 |
* @param string body of the request
|
|
|
46 |
* @param array headers for the request
|
|
|
47 |
* @return mixed either
|
|
|
48 |
*/
|
|
|
49 |
function sendRequest( $url, $body, $headers )
|
|
|
50 |
{
|
|
|
51 |
$curl = curl_init($url);
|
|
|
52 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
53 |
curl_setopt($curl, CURLOPT_POST, 1);
|
|
|
54 |
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->_createHeaders($headers));
|
|
|
55 |
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
|
|
|
56 |
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
57 |
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
|
|
58 |
|
|
|
59 |
$result = curl_exec($curl);
|
|
|
60 |
|
|
|
61 |
if ($result === false) {
|
|
|
62 |
throw new Services_Ebay_Transport_Exception(curl_error( $curl ));
|
|
|
63 |
}
|
|
|
64 |
return $result;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* create the correct header syntax used by curl
|
|
|
69 |
*
|
|
|
70 |
* @access private
|
|
|
71 |
* @param array headers as supplied by Services_Ebay
|
|
|
72 |
* @return array headers as needed by curl
|
|
|
73 |
*/
|
|
|
74 |
function _createHeaders( $headers )
|
|
|
75 |
{
|
|
|
76 |
$tmp = array();
|
|
|
77 |
foreach ($headers as $key => $value) {
|
|
|
78 |
array_push($tmp, "$key: $value");
|
|
|
79 |
}
|
|
|
80 |
return $tmp;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
?>
|