PHP 获取受密码保护的 REST 数据快照信息


PHP to get password-protected REST datasnap information

我有以下代码可以从DataSnap服务器获取一些信息:

<?php
    $username = USERNAME
    $password = PASSWORD
    $service_url = 'http://200.206.17.34:81/datasnap/rest/TServerMethods1/blogin/';
    $curl = curl_init($service_url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    $curl_response = curl_exec($curl);
    echo $curl_response;
    if ($curl_response === false) {
        $info = curl_getinfo($curl);
        curl_close($curl);
        die('Error occured during curl exec. Additional info: ' . var_export($info));
    }
    curl_close($curl);
    $decoded = json_decode($curl_response);
    if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
        die('Error occured: ' . $decoded->response->errormessage);
    }
    echo 'Response ok!';
    var_export($decoded->response);
?>

当我运行这个时,我得到的是:

array ( 'url' => 'http://200.206.17.34:81/datasnap/rest/TServerMethods1/blogin/', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 0, 'namelookup_time' => 0.0002249999999999999938417316602823348148376680910587310791015625, 'connect_time' => 0, 'pretransfer_time' => 0, 'size_upload' => 0, 'size_download' => 0, 'speed_download' => 0, 'speed_upload' => 0, 'download_content_length' => -1, 'upload_content_length' => -1, 'starttransfer_time' => 0, 'redirect_time' => 0, 'redirect_url' => '', 'primary_ip' => '200.206.17.34', 'certinfo' => array ( ), )Error occured during curl exec. Additional info:

我做错了什么?

--编辑:

我可以使用浏览器和wget连接到该地址。

来自

curl_info的数据表示连接到服务器时出现问题,例如,"'content_type' => NULL, 'http_code' => 0" 等。

尝试在关闭第一个 if 语句中的 $curl 处理程序之前插入print curl_error($curl)以获取更多信息。