Ejemplo n.º 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;
}
Ejemplo n.º 2
0
function find_and_decode_xml($buf, $debug)
{
    $retval = '';
    // JDW fix
    if (strlen($buf)) {
        $xml_begin = substr($buf, strpos($buf, "<?xml"));
        if (strlen($xml_begin)) {
            $retval = xmlrpc_decode($xml_begin);
        } else {
            dbg1("xml start token not found", $debug);
        }
    } else {
        dbg1("no data", $debug);
    }
    return $retval;
}
Ejemplo n.º 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;
}