Viewed   67 times

I need to translate this cURL command into PHP cURL code:

> curl --get '' --data
> 'cursor=-1&screen_name=somename' --header 'Authorization: OAuth
> oauth_consumer_key="key", oauth_nonce="nonce",
> oauth_signature="signature", oauth_signature_method="HMAC-SHA1",
> oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"'
> --verbose

I have tried this, but it doesn't seem to work:

> $ch = curl_init();
> curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth oauth_consumer_key="key", oauth_nonce="nonce", oauth_signature="signature", oauth_signature_method="HMAC-SHA1", oauth_timestamp="timestamp", oauth_token="token", oauth_version="1.0"'));
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
> curl_setopt($ch, CURLOPT_VERBOSE, 1);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_HTTPGET, 1);
> curl_setopt($ch, CURLOPT_URL, '');
> $page = curl_exec($ch);
> curl_close($ch);

error i am getting

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

however it works in the standard curl command



You need to provide curl with the certificate chain that will allow it to verify Twitter's SSL certificate as valid. To do this, download the requisite certificate signatures from here and save them into a plain file (I 'll assume you name it cacert.pem).

Then, before making the request, set CURLOPT_CAINFO to point to this file:

// assumes file in same directory as script
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');

It's also a good idea to explicitly enable SSL certificate verification instead of relying on default settings:

curl_setopt($ch, CURLOPT_VERIFYPEER, true);
Thursday, October 20, 2022

cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.

This might be symptomatic of a self signed certificate being used.

What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt.

What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, which will disable the check that is failing.

You really should use the first option.

Wednesday, August 31, 2022

you should check examples from here

Bellow is the code for you case,

$url = "http://build:[email protected]:8080/job/android-test/buildWithParameters";     
$data = "POST_RESULTS=true&RUN_ID=".$testrun_id."&CHECK_NAME=SampleAutomatedPlan";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
Saturday, October 15, 2022

From :

-k, --insecure: (SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used.

Looking further at reading SSL page with CURL (php), this tells you that you have to set CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST to FALSE. This basically overrides the "security checks".

I think that's what you need to mirror the --insecure command line option.

Monday, December 12, 2022

301 is a redirect response code. Add this line:


...after curl_init() and before curl_exec() to have cURL follow the redirect to the correct location.

The -X option is used to specify the POST method in your original command string, which you have mirrored with curl_setopt($ch, CURLOPT_POST, 1);


Try this code:

$username = "[email protected]";
$password = "PASSWORD";
$target_url = ""

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result = curl_exec($ch);
curl_close ($ch);
echo $result;
Wednesday, November 16, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :