2016-07-08 86 views
1

我正在嘗試使用DocuSign API創建recipientView。我試圖使用捲曲庫郵政PHP請求,但出於某種原因低於我的代碼執行我的代碼時,行$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);將返回0:

$url = "http://demo.docusign.net/restapi/v2/accounts/$account_id/envelopes/ 
     $envelope_id/views/recipient"; 

$body = array("returnUrl" => "http://www.docusign.com/devcenter", 
       "authenticationMethod" => "None", 
       "email" => "$recipient", 
       "userName" => "$recipient"); 

$body_string = json_encode($body); 

$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Accept: application/json', 
    'Content-Type: application/json', 
    'Content-Length: '.strlen($body_string), 
    'Authorization: Bearer '.$access_token 
)); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string); 

$json_response = curl_exec($curl); 

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

echo $status; 

$response = json_decode($jason_response, true); 
$url = $response["url"]; 

我通過JSON和發送POST的我應該得到的迴應是JSON。爲什麼我的curl_exec()出現故障,並且正在製作$status = 0

+1

嘗試在'curl_exec'調用之後添加'curl_error($ curl)',看看是否返回任何錯誤消息。 –

+0

當這樣做的錯誤是:無法連接到demo.docusign.net端口80:連接被拒絕 – Jodo1992

+0

這就是問題所在。我添加了這個信息的答案。 –

回答

3

的原因您的錯誤信息

Failed to connect to demo.docusign.net port 80: Connection refused 

是您正在試圖連接到HTTP端口80,但docusign.net只聽HTTPS端口443

更改API URL從http://https://並且您應該設置並且curl_getinfo()也會返回正確的值。

0

您沒有包含身份驗證標頭。每個對API的調用都需要進行身份驗證。

Docs about Authentication options

+0

即使我添加一個認證頭(使用訪問令牌),我也會得到相同的響應。我更新了我的問題。 – Jodo1992

0

當存在時curl_exec錯誤,的curl_getinfo($curl, CURLINFO_HTTP_CODE);結果將是零。既然你發現curl_error返回以下:

無法連接到demo.docusign.net 80端口:連接被拒絕

結果爲零。

你必須弄清楚爲什麼DocuSign拒絕你的連接(檢查他們的API文檔)。一旦你找出並解決它,你應該得到一個正確的JSON結果,並有一個有效的HTTP狀態代碼。