天天看點

php發送get請求

感謝:http://www.zoneself.org/2014/07/21/content_2665.html

1.用PHP發送get請求,很簡單:

   <?php 

       $url='http://www.domain.com'; 

       $html = file_get_contents($url);

       echo $html;

  ?>

   就這樣就可以發送get請求,并擷取傳回資訊,不過這僅限于普通的http請求

   若要發送https請求,這樣就會報錯:Unable to find the wrapper “https”

        Windows下:在php.ini中找到并修改

                         ;extension=php_openssl.dll (去掉前面的逗号)

                         重新開機服務就可以了;

        Linux下的PHP,就必須安裝openssl子產品,安裝好了以後就可以訪了。

<?php

      function getSslPage($url) {

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

            curl_setopt($ch, CURLOPT_HEADER, false);

            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_REFERER, $url);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

            $result = curl_exec($ch);

            curl_close($ch);

            return $result;

      }

      //調用

      echo getSslPage($url);

?>

Qt

繼續閱讀