Curl is not working on my localhost

Asked

Viewed 597 times

0

I have a code in PHP to list a stock in OLX.

In production it works perfectly.

at Curl location is not working at all.

$url = 'https://apps.olx.com.br/autoupload/published';
$ch = curl_init($url);
$payload = json_encode(array('access_token' => $pacote['token']));

curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=UTF-8'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
print_r(curl_getinfo($ch));
curl_close($ch);

yes, phpinfo info has Curl running:

cURL support    enabled
cURL Information    7.24.0

the command print_r(curl_getinfo($ch)); has the following output.

Array ( [url] => https://apps.olx.com.br/autoupload/published [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.016 [namelookup_time] => 0.016 [connect_time] => 0.016 [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.233.83.19 [primary_port] => 443 [local_ip] => 10.25.61.90 [local_port] => 65055 [redirect_url] => ) 

the code $data = curl_exec($ch); false return.

Repeating this code in production returns a list perfectly. I’m using windows 10. php 5.4.45.

2 answers

0

I made following code:

        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: 

application/json;charset=UTF-8')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);= curl_exec($ch); print_r(curl_getinfo($ch)); $Response = curl_error($ch); echo slastripshes($Sponse); curl_close($ch);insira o código aqui

Result echo striplashes($Sponse) was

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

Or Be so set up SSL or try without it.

0


The [http_code] => 0 indicates that it is an internal Curl error, it is probably related:

  • Problem with TLS/SSL:

    • No Openssl installed (or outdated);
    • Did not define the Certificate Authorities reliable (does not have a Cabundle);
  • Problem in the DNS:

    • No DNS defined and no DNS defined by default.

There are other problems, but this was not included in your answer, these are the most common.


The solution for TLS/SSL can be to install an Openssl (or enable it) and define a Cabundle. Disconnect the CURLOPT_SSL_VERIFYPEER may be an option, but this leaves you vulnerable to MITM.

The best option is to go on https://curl.haxx.se/docs/caextract.html (or obtain the certificate from the authority that issued the certificate from the specific website) and then specify:

curl_setopt($ch, CURLOPT_CAINFO, 'caminho/para/cacert.pem');

For DNS you can choose to use Doh (DNS-over-HTTPS) in the latest versions of Curl. Honestly, I don’t know if PHP already supports this (if not, maybe in a few years this will be a valid solution).

curl_setopt($ch, CURLOPT_DOH_URL, 'https://1.1.1.1/dns-query');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.