dqjcb132285 2016-05-04 11:55
浏览 26

Json从URL到curl到PHP

Is it possible I'm doing something wrong with the authentication part since this piece of code returns NULL

$url =  "sample.com/api_sample";
$username = "********";
$password = "********";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);

$result = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);

curl_close($ch);

$data = json_decode( $result, true );

var_dump($data);

This is what my json looks like so i think there is nothing wrong with the url i forward to curl

enter image description here

I have to mention that the page loads for quite some time (5-10 min) until it outputs NULL

EDIT: This is what curl_getinfo($ch) outputs

 array(26) { ["url"]=> string(69) 

"http://luceed.euromdenis.hr:8081/datasnap/rest/partneri/naziv/tomsoft" 
["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0)
["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0) ["total_time"]=> float(188.461785) 
["namelookup_time"]=> float(0.252828) ["connect_time"]=> float(0) 
["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=>
 float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) 
["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) 
["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["certinfo"]=> 
array(0) { } ["primary_ip"]=> string(0) "" ["primary_port"]=> int(0) 
["local_ip"]=> string(0) "" ["local_port"]=> int(0) ["redirect_url"]=> string(0) 
"" }

EDIT 2: print curl_error($ch) outputs

Failed to connect to luceed.euromdenis.hr port 8081: Connection timed out
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题