Пример #1
0
function xu_rpc_http_curl($method_name, $args, $url, $debug = false)
{
    if ($url) {
        $request = xmlrpc_encode_request($method_name, $args);
        $content_len = strlen($request);
        preg_match('/^(.*?\\/\\/.*?) (\\/.*)/', $url, $matches);
        $hostport = $matches[1];
        $uri = $matches[2];
        dbg1("opening curl to {$url}", $debug);
        $http_request = "POST " . $uri . " HTTP/1.0\r\n" . "User-Agent: xmlrpc-epi-php/0.2 (PHP) \r\n" . "Content-Type: text/xml\r\n" . "Content-Length: {$content_len}\r\n" . "\r\n" . $request;
        dbg1("sending http request:</h3> <xmp>\n{$http_request}\n</xmp>", $debug);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $hostport);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_request);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $response_buf = curl_exec($ch);
        curl_close($ch);
        dbg1("got response:</h3>. <xmp>\n{$response_buf}\n</xmp>\n", $debug);
        $retval = find_and_decode_xml($response_buf, $debug);
    }
    return $retval;
}
Пример #2
0
/**
 * @param params   a struct containing 3 or more of these key/val pairs:
 * @param host		 remote host (required)
 * @param uri		 remote uri	 (required)
 * @param port		 remote port (required)
 * @param method   name of method to call
 * @param args	    arguments to send (parameters to remote xmlrpc server)
 * @param debug	 debug level (0 none, 1, some, 2 more)
 * @param timeout	 timeout in secs.  (0 = never)
 * @param user		 user name for authentication.  
 * @param pass		 password for authentication
 * @param secure	 secure. wether to use fsockopen_ssl. (requires special php build).
 * @param output	 array. xml output options. can be null.  details below:
 * @param nodecode       if true then don't find_and_decode_xml
 *
 *     output_type: return data as either php native data types or xml
 *                  encoded. ifphp is used, then the other values are ignored. default = xml
 *     verbosity:   determine compactness of generated xml. options are
 *                  no_white_space, newlines_only, and pretty. default = pretty
 *     escaping:    determine how/whether to escape certain characters. 1 or
 *                  more values are allowed. If multiple, they need to be specified as
 *                  a sub-array. options are: cdata, non-ascii, non-print, and
 *                  markup. default = non-ascii | non-print | markup
 *     version:     version of xml vocabulary to use. currently, three are
 *                  supported: xmlrpc, soap 1.1, and simple. The keyword auto is also
 *                  recognized to mean respond in whichever version the request came
 *                  in. default = auto (when applicable), xmlrpc
 *     encoding:    the encoding that the data is in. Since PHP defaults to
 *                  iso-8859-1 you will usually want to use that. Change it if you know
 *                  what you are doing. default=iso-8859-1
 *
 *   example usage
 *
 *                   $output_options = array('output_type' => 'xml',
 *                                           'verbosity' => 'pretty',
 *                                           'escaping' => array('markup', 'non-ascii', 'non-print'),
 *                                           'version' => 'xmlrpc',
 *                                           'encoding' => 'utf-8'
 *                                         );
 *                   or
 *
 *                   $output_options = array('output_type' => 'php');
 */
function xu_rpc_http_concise($params)
{
    $host = $uri = $port = $method = $args = $debug = null;
    $timeout = $user = $pass = $secure = $debug = $nodecode = null;
    extract($params);
    // default values
    if (!$port) {
        $port = 80;
    }
    if (!$uri) {
        $uri = '/';
    }
    if (!$output) {
        $output = array('version' => 'xmlrpc');
    }
    $response_buf = "";
    if ($host && $uri && $port) {
        $request_xml = xmlrpc_encode_request($method, $args);
        $response_buf = xu_query_http_post($request_xml, $host, $uri, $port, $debug, $timeout, $user, $pass, $secure);
        if ($nodecode) {
            $retval = $response_buf;
        } else {
            $retval = find_and_decode_xml($response_buf, $debug);
        }
    }
    return $retval;
}
Пример #3
0
function xu_rpc_http_concise_curl($arrayParam)
{
    // 1) set up variables and verify.
    extract($arrayParam);
    if (!isset($boolSecure)) {
        $boolSecure = false;
    }
    if (!isset($boolDebug)) {
        $boolDebug = false;
    }
    if (!isset($objOutput)) {
        $objOutput = array(version => "xmlrpc");
    }
    if (isset($txtMethod) and isset($txtURL) and isset($txtHost) and isset($intPort) and isset($txtURI)) {
        // 2) xmlrpc encode request.
        $txtRequest = xmlrpc_encode_request($txtMethod, $arrayArgs, $objOutput);
        $intContentLen = strlen($txtRequest);
        dbg1("opening curl to {$txtURL}", $boolDebug);
        $txtTransport = 'HTTPS';
        if ($boolSecure) {
            $txtTransport = 'HTTPS';
        }
        $txtHTTP_Request = "POST {$txtURI} {$txtTransport}/1.0\r\n" . "User-Agent: xmlrpc-epi-php/0.2 (PHP) \r\n" . "Content-Type: text/xml\r\n" . "Content-Length: {$intContentLen}\r\n" . "\r\n" . "{$txtRequest}";
        dbg1("sending http request:</h3> <xmp>\n{$txtHTTP_Request}\n</xmp>", $boolDebug);
        // 3) open CURL, and send data.
        $objCURL = curl_init($txtURL);
        curl_setopt($objCURL, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($objCURL, CURLOPT_CUSTOMREQUEST, $txtHTTP_Request);
        curl_setopt($objCURL, CURLOPT_HEADER, 0);
        if ($a_boolSecure) {
            curl_setop($objCURL, CURLOPT_SSLVERSION, 3);
        }
        //  4) read response, and close CURL.
        $txtResponse = curl_exec($objCURL);
        curl_close($objCURL);
        dbg1("got response:</h3>. <xmp>\n{$txtResponse}\n</xmp>\n", $boolDebug);
        //  5) xmlrpc decode result.
        $objReturn = find_and_decode_xml($txtResponse, $boolDebug);
    }
    //  6) return result.
    return $objReturn;
}