enter image description hereI have designed gcm server in php(MAMP). curl version-7.43.0,php version 7.0.0 .The code for server-
<?php
function send_push_notification($registration_id,$message){
define('API_KEY','AIzaSyAoFih8qEFlOis3vVWhsxxlLxxxxxxxxxx');
$url='https://gcm-http.googleapis.com/gcm/send';
$fields=array(
'registration_id'=>$registration_id,
'data'=>$message,
);
$headers=array(
'Authorization:key='.API_KEY,
'Content-Type:application/json'
);
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
echo $result;
}
?>
<?php
send_push_notification("e2DgrsZPGKU:APA91bF_73a6-o5CLV-gdcZzYFAbtikJqi-5w6gDSCaRa4z8-1iGLeV5SS6hQkW8pj_g_DxBe7JLDsOPMGu3y1GkKw1vpn_ZEWIeCwbSITpd0pLwaz50W8uzHKNghvnf1xxxxxxxxxxx","hi");
?>
When I try running this php script in my browser it shows following error
Curl failed: Unknown SSL protocol error in connection to
gcm-http.googleapis.com:443
I have disabled SSL verification,still it shows curl error.
Changing SSL version to 6 worked for me.
curl_setopt($ch,CURLOPT_SSLVERSION,6);
Related
I try to connect to socks5 proxy using libcurl, however I receive the answer SOCKS: authentication failed. I also tried to connect to the proxy server through a Powershell script with cURL – it works, so the proxy server is available and my login and password are correct. I tried a lot of solutions... But connection via PHP-script still does not work.
PHP version – 5.4, cURL version – 7.19. What can I do?
[UPDATE] Here is my current code. I want to send message with my Telegram bot :)
$proxy = '<hostname>:<port>';
$proxy_auth = '<username>:<password>';
$url = 'https://api.telegram.org/bot<botID>/sendMessage?'.'chat_id='.$chat_id.'&parse_mode='.$parse_mode.'&text='.'test';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_auth);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $curl_scraped_page;
curl_close($ch);
Here is the complete answer for anyone else having the same issue.
//Curl setup
$url = "https://google.com";
$proxy = "10.23.2.2:8080";
$password = "username:secret_passowrd";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_HEADER, true);
//proxy's address
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//proxy's password
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $password);
//in order to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//in order to use the result of the query
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//run query
$curl_scraped_page = curl_exec($ch);
$error = curl_error($ch);
echo $error;
echo $curl_scraped_page;
curl_close($ch);
Hope that helps.
I am having difficulty curling an HTTPS url that uses TLS 1.2, in my curl operation- I post my login data into the website and save it in cookiefile. The error message I am getting is this:
"API Error:SSL connect error"
I have tried setting curl_setopt($ch, CURLOPT_POST) to 6 but that does not seem to work, any suggestions?
Versions I am using:
OpenSSL version is 1.0.2b
CURL version is 7.49.1
PHP is 5.5
Here is the code:
public function curl_request($url, $data, $method = 'GET', $headers = array(), $ssl_verify = false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $ssl_verify);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl_verify);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_HTTP200ALIASES, range(400, 599));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
if ($method == 'POST')
{
curl_setopt($ch, CURLOPT_POST, 6);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$resp = curl_exec($ch);
if(curl_errno($ch))
{
throw new Exception('Unleashed API Error:' . curl_error($ch));
}
//print("<pre>" . print_r($resp, true). "</pre>")
$info = curl_getinfo($ch);
curl_close($ch);
$output = array();
$output['resp'] = $resp;
$output['info'] = $info;
OpenSSL version is 0.9.8b
There is no support for TLS 1.2 in OpenSSL 0.9.8. You need at least OpenSSL version 1.0.1.
When i am making a payment in paypal, its throws "SSL connect error (35)", even i have a enabled TLS. And also i have tested with "https://tlstest.paypal.com", is also return same error.
Following sample i used to test TLS.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://tlstest.paypal.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
$result = curl_exec($ch);
echo 'result = '.$result.'<br>';
echo 'errno = '.curl_errno($ch).'<br>';
echo 'error = '.curl_error($ch).'<br>';
curl_close($ch);
Thanks in advance
I'm using curl to send an xml file over https to the rightmove API - they supplied me with all the certificates.
I am getting the error :
60SSL certificate problem: unable to get local issuer
certificateResult =
I have tried everything i have found on every other stackoverflow post similar and nothing is working, i have tried downloading the old cacert.pem and changed the files in php.ini - ive installed my personal information file andcreated a certificate on the browser and local machine and nothing is removing the error 60.
This is my PHP :
<?php
$xml = file_get_contents("myxml.xml");
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__).'\mypem.pem');
curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE , 1);
$ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
echo "Result = ".$ch_result;
curl_close($ch);
?>
this has had me banging my head for days, i would be very grateful for any assistance.
For my particular case i needed to add the keyfile, sslcert and cert password.
//$xml = file_get_contents("thexmlfile.xml");
$xml= $propertyXml->asXML();
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . '\pemfile.pem');
curl_setopt($ch, CURLOPT_URL, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, getcwd() . '\myjks.jks');
curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . '\pemfile.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "thesslpassword");
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, "https://adfapi.adftest.rightmove.com/v1/property/sendpropertydetails");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE , 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$ch_result = curl_exec($ch);
print curl_errno($ch);
print curl_error($ch);
echo "Result = ".$ch_result;
curl_close($ch);
It is failing as curl is unable to verify the certificate provided by the server.
There are two options to get this to work:
1 Allows curl to make insecure connections, that is curl does not verify the certificate.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
2 Add the root CA (the CA signing the server certificate) in php.ini
curl.cainfo=/path/to/cacert.pem
You should use option 2 as thats the option that ensures that you are connecting to secure ftp server.
I was getting the same "SSL certificate problem: unable to get local issuer certificateResult" error with HTTP GET to a remote https site. I only needed to provide the CA cert to php curl, ie CURLOPT_CAINFO:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CAINFO, "/path/to/CA_Bundle.crt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
print "curl_error: $error_msg <br>";
} else {
print "output: $output<br>";
}
curl_close($ch);
I am trying to add information into the rest web service at a particular port number: 8999. On localhost, it is working fine but on the live server, it gives the following error:
cURL Error (28): connect() timed out!
Here is the code
$ch = curl_init('http://int.otono-me.com:8999/api/customers/new');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_PORT, 8999);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"X-Auth-Token: " . $_SESSION["Token"]
));
$result = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
} else {
echo "Successful\n";
}
curl_close($ch);
echo $result;
Any suggestion on what needs to be done?
Either you have a proxy on the live system,
or a firewall in between.
Ask your local sysop for changes regarding firewall.
You are also missing a ':
$ch = curl_init('http://int.otono-me.com:8999/api/customers/new');
// -------^
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://int.otono-me.com:8999/api/customers/new");
also your link is not answering
Don't implement your PORT in your URL. Send separatelly URL and PORT:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://int.otono-me.com/api/customers/new");
curl_setopt($ch, CURLOPT_PORT, 8999);