linslin / Yii2-Curl

:curly_loop: Yii2 Curl extension based on PHP cURL.
179 stars 93 forks source link

Curl not giving me any response #72

Closed devexpart closed 6 years ago

devexpart commented 6 years ago

I am trying to use a GET method to carry of some data from the a URL. I am trying to get a code from a URL by following this Zoho Link

Below is my code

`$curl = new curl\Curl();
    $response = $curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
    ])
        ->get('https://accounts.zoho.com/oauth/v2/auth');

    if ($curl->errorCode === null) {
        echo $response;
    } else {

        echo '<pre>';print_r($curl->errorCode);
    }
    exit();`

I am using POSTMAN for testing my API but all I see a empty screen. I have also put this question on StackOverFlow.

Can anyone please help me out

linslin commented 6 years ago

It's working quite fine when you enable SSL and check the response code / response header to redirect to the userAuth form on Zuhu:

$curl = new Curl();

/** @var Curl $response */
$curl->setGetParams([
        'scope' => 'ZohoBugTracker.projects.ALL,ZohoBugTracker.bugs.ALL',
        'client_id' => '1000',
        'response_type' => 'code',
        'access_type' => 'offline',
        'redirect_uri' => 'http://11.111.111.111:7000/api/oauth/zoho_auth',
])->setOption(CURLOPT_SSL_VERIFYPEER, true)
    ->setOption(CURLOPT_SSL_VERIFYHOST, false)
    ->setOption(CURLOPT_CAINFO, 'C:/Ampps/apache/conf/ssl_crt/cacert.pem')
    ->get('https://accounts.zoho.com/oauth/v2/auth');

$responseHeaders = $curl->responseHeaders;

if ($curl->responseCode === 302 && isset($responseHeaders['Location'])) {
    header("location: ".$responseHeaders['Location']);
    die();
}

I also answered this on stackoverflow. Feel free to accept this answer :).

linslin commented 6 years ago

Solved