尝试将curl的get请求发送到hellosign API

时间:2013-07-25 03:53:51

标签: php curl

当我在浏览器中输入内容时:'https://myemail:mypassword@api.hellosign.com/v3/account'

我得到了

{"account":{"account_id":"**************","email_address":"myemail","callback_url":null,"role_code":null}} 

似乎是一个有效的回复。

我正在尝试使用libcurl php库在php中实现这一点。我有以下内容,但是当我在$ response变量上运行var_dump时得到FALSE。关于libcurl设置的任何想法?我尝试使用和不使用认证子字符串'myemail:mypassword的base_64编码对整个字符串进行urlencoding。提前致谢:

$final_string= 'https://myemail:mypassword@api.hellosign.com/v3/account';    

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, 'HelloSign-PHP');
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_URL, $final_string);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::$time_out); 

$response = curl_exec($curl);

    // Get the status code
    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    if(curl_exec($curl) === false)
        {
            echo 'Curl error: ' . curl_error($curl);
        }
        else
        {
            echo 'Operation completed without any errors';
        }

curl_close($curl);


output is : 

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failedProblem connecting to HelloSign.

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

<?php

$api_key = 'YOUR_API_KEY';
$url = 'https://api.hellosign.com/v3/account';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":"); // Normally you'd put a password after the colon, but you don't need it if you're using an API key
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$response_json = json_decode($response, true);

print_r($response_json);

curl_close($ch);

?>

注意:您不需要使用API​​密钥(您可以使用您的用户名和密码,如上所述),但建议您使用。您可以在此处检索您的API密钥:https://www.hellosign.com/home/myAccount#api