1

I'm trying to create connection between two system, one of them is main. The connection will be provided throught cURL. I have this function:

private function build_post($url, $params, $authentificate = true) {

    //url-ify the data for the POST

    $params_string= http_build_query($params);

    $curl = curl_init($url);

    //set the url, number of POST vars, POST data
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl,CURLOPT_POST, count($params));
    curl_setopt($curl,CURLOPT_POSTFIELDS, $params_string);

    if ($authentificate) {
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'x-api-key: key1',
            'x-api-skey: key2'
        ));
    }

    //execute post
    $curl_response = curl_exec($curl);

    if ($curl_response === false) {
        $info = curl_getinfo($curl);
        curl_close($curl);
        echo('error occured during curl exec. Additioanl info: '.var_export($info));
        }
    else
    {
        echo 'Responze OK';
        curl_close($curl);
    }
}

From the system where I am trying to connect, I only have 2insctructions:

Each request to REST API must be authenticated by providing valid access & secret key of sender in request header.

for example:

x-api-key: D6d03y3h0iEW7Iz3xW9127a0xrh1ib

x-api-skey: sc1vcOTTFLuqjFa5u08UKtKaWl48XSqlm8jMQvrnXnuPvRjqTPgIDI6P1YcR

and second instruction is how should requested post look like.

I have no idea what is going wrong, all the time i get this:

array ( 'url' => 'https://rest.api.profitee.com/public/subscribe', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 1, 'redirect_count' => 0, 'total_time' => 0.037060000000000002662314813051125383935868740081787109375, 'namelookup_time' => 0.0003939999999999999817472395857720357525977306067943572998046875, 'connect_time' => 0.037070999999999999785504911642419756390154361724853515625, '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' => '54.229.78.229', 'redirect_url' => '', )error occured during curl exec. Additioanl info: NULL

Can someone help me make it work? Thanks

5
  • Are u getting any error ? Commented Jan 17, 2014 at 12:09
  • Nope this array is all i get... Commented Jan 17, 2014 at 12:09
  • You have an error in the response "error occured during curl exec. Additioanl info: NULL", can u use curl_error($curl_response); this may give u more information Commented Jan 17, 2014 at 12:13
  • I get: error occured during curl exec. Additioanl info: SSL peer certificate or SSH remote key was not OK Commented Jan 17, 2014 at 12:18
  • Added a solution try this. Commented Jan 17, 2014 at 12:35

1 Answer 1

3

Add the following lines and see if it works.

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);  
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
Sign up to request clarification or add additional context in comments.

3 Comments

Didn't work, but i after i changed verifyhost to false, i get "Failed to verify user and domain. Thread was being aborted." So I'm going to change some emails with them...Still thanks very much :)
sure ! Usually the ssl certificate issue create this sort of problem, keep posted what solution they give from their end. Would be interesting to see that.
FYI - those settings will leave you open to potential MITM attacks: stackoverflow.com/questions/13740933/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.