doumanni3501 2016-11-11 11:31
浏览 106
已采纳

curl与基本的http auth无法正常工作

I'm trying to connect to a WS using curl. My code :

$url ="https://example?param=ee&param2=rr";
$headers = array(
'Content-Type:application/json',
'Authorization: Basic '. base64_encode("username:password") // <---
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_HEADER,true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

//curl_setopt($curl, CURLOPT_USERPWD, 'username:passwrd');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);

I get this error:

 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 
 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 
 'redirect_count' => 0, 'total_time' => 0.051353999999999997, 
 'namelookup_time' => 0.0032659999999999998, 
 'connect_time' => 0.051365000000000001, '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, 'certinfo' => array ( ), 
 'primary_ip' => '185.18.224.30', 'primary_port' => 443, 
 'local_ip' => '172.23.155.94', 'local_port' => 44608, 
 'redirect_url' => '', )error occured during curl exec.

I can't figure out the error in my code. Have a missed a parameter?

  • 写回答

2条回答 默认 最新

  • ds0678 2016-11-11 11:44
    关注

    Try to add:

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    

    By default when you use HTTPS protocol, CURL checks SSL sertificate on your server and gives an error if it is not valid. The line above turns this off.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思