我正在嘗試使用curl連接到WS。 我的代碼:使用基本http身份驗證無法正常工作
$url ="https://example?param=ee¶m2=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);
我得到這個錯誤:
'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.
在我的代碼我無法找出錯誤。錯過了一個參數?
作者:WS你是指網站,而不是.ws網站? – Martin
您沒有使用CURLOPT_USERPWD的原因,而不是自己組裝授權頭? – CBroe
它在標題數組上設置 –