SSL Certificate request with cURL

大憨熊 提交于 2019-12-11 12:09:32

问题


I'm writing a betting bot in PHP and the bet house requires a SSL Certificate being sent for automated connections.

I've got all kinds of self-signed certificates to use: cert.crt, cert.pem, cert.p12 and also a key cert.key and I'm using curl to establish the login connection however I can't seem to get the curl parameters right for the connection.

With the following command line I can establish a successful connection:

curl -q -k --cert cert.crt --key cert.key https://api.domain.com/certificatelogin/endpoint -d "username=UUUUUUU&password=XXXXXXX" -H "X-Application: appKey"

And this one works too:

curl -q -k --cert cert.pem https://api.domain.com/certificatelogin/endpoint -d "username=UUUUUUU&password=XXXXXXX" -H "X-Application: appKey"

The PHP code I'm currently using is as follows:

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.domain.com/certificatelogin/endpoint");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-Application: ' . $appKey,
        'Accept: */*',
        'Content-Type: application/x-www-form-urlencoded'
    ));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_SSLCERT, "path/to/cert/cert.pem");

    $postData = 'username=UUUUUUUUU&password=XXXXXXXXXXX';

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    $response = json_decode(curl_exec($ch));
    echo 'Response: ' . json_encode($response);

And after trying so many combinations with .crt and .key can't seem to make anything work at all.

Any help would be greatly appreciated. :)

来源:https://stackoverflow.com/questions/19388508/ssl-certificate-request-with-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!