简体   繁体   中英

PHP cURL is not working on Xampp Windows 10

I am using curl to fetch data from different web service hosted on different location on the web. I am trying to fetch the data to my localhost.

    $token1="SOMETOKENXX";
    $mobileNumber= $_POST['number'];

        $postData = array(
            'mobile' =>$mobileNumber
        );
        $service_url ='http://api.hashtagloyalty.in/merchants/users/users_profile';
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $service_url);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_PORT, 8080);
        curl_setopt($curl, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17");
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postData));
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json','Authorization:'.$token1));
        $curl_response = curl_exec($curl);

//        echo($curl_response);



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

        curl_close($curl);

I am not able to fetch the result on xampp localhost but working on GoDaddy live server.

I am working on latest version of xampp 7.2.6 and Windows 10 OS

I am accessing my localhost on port 8080 means my localhots url is localhost:8080 .

How can I know if something is blocking my request? There is no result and giving empty result.

Please help

error

array ( 'url' => 'http://api.hashtagloyalty.in/merchants/users/users_profile', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 20.204, 'namelookup_time' => 1.0E-6, 'connect_time' => 0.0, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array ( ), 'primary_port' => 0, 'local_ip' => '', 'local_port' => 0, )error occured during curl exec. Additioanl info:

Probably a firewall issue
cURL uses port 1080 which is probably not open

Several fixes:
Open port 1080 in your firewall/router

or

Specify a (working) port for cURL
curl_setopt($curl, CURLOPT_PORT, PortYouWantHere)

curl is not working because my organisation's proxy is blocking the request. So I have added the below code and it worked like charm :)

curl_setopt($ch, CURLOPT_PROXY, $proxyhostandpass); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyusernamepass);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM