11
Trying to run Curl in PHP gives me this error..
SSL: no Alternative Certificate Subject name Matches target host name 'xxx'
I would like to better understand this, and even debug the problem.
$arr["oi"] = "tchau";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.xxx.com/teste/recebe_requisicao.php");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
curl_exec($ch);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
echo json_encode($info);
However, the return of curl_getinfo is this:
"http_code":0
There are other variables also returned, but I don’t understand which one is important to check.
The request is made from server to itself.. Note that other sites on the same machine do not give this error.
EDIT:
I did tests using POSTMAN, and then the requisition worked.
I do not understand why my server request for itself gives SSL error, however POSTMAN for it is OK.
Funny that other sites from the same server are OK, no error....
EDIT 2
POSTMAN generated code to use in PHP with the Curl library
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.xxx.com/teste/recebe_requisicao.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POSTFIELDS => "ola=valor",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: 70cfc5b2-fd30-4605-ae73-b96c5cae0a92",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
EDIT 3
I exchanged SSL Lets Encrypt for a Paid I already had, just for conscience disengagement, but apparently did not solve..
I have uninstalled, installed SSL Lets Encrypt to check if this was not the problem.
– Ale
Maybe ssl may be having problems setting up, you can use this site (ssllabs.with) to test, check the information
Chain issues
, Obs. on this site you can hide the results by marking thecheckbox
Do not show the Results on the Boards. Another thing, as this requisition is local would not be better usedhttp://localhost/
– Icaro Martins
Why are you making a server request for yourself? It wouldn’t be enough to make one
require
or even run the PHP file by functionexec
?– Costamilam
@Icaromartins SSL is OK, the problem. The problem has been solved! And it wasn’t in SSL, because I installed and reinstalled it 5 times (Cpanel, Encrypt Lets and even 1 paid). So I talked to the Host administrator, and it looks like there was an internal DNS problem (in the hosts file), so ADM switched to the server IP (there was another one, nothing to see), and it worked! If any of you manage to post a response to the case, including #1 solution: SSL error, and #2 solution, DNS error with a plausible explanation, you will be rewarded.
– Ale
@Guilhermecostamilam Yes could, and would save more resources(less requisition), but I like to work that way! It doesn’t compromise, it doesn’t affect, and if I ever notice that it’s consuming, I perfect it.
– Ale