2016-04-25 51 views
1

我有以下代码从一个DataSnap服务器的一些信息:PHP获取密码保护REST的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的连接地址。

回答

0

从curl_info的数据表明连接到服务器的一个问题,例如, “ 'HTTP_CODE'=> 0 'CONTENT_TYPE'=> NULL” 等

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

+0

我得到'无法连接到hostarray' –

+0

端口81是否在主机上打开?它似乎是一所大学,他们的安全政策默认情况下通常是相当严格的。另外,尝试用'curl_setopt($ curl,CURLOPT_PORT,'81');'而不是通过'$ service_url'变量来设置端口号。 –

+0

我可以从我的浏览器连接到它,它是PHP不能的,而且这样做也不起作用。 –