zoukankan      html  css  js  c++  java
  • 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”

       

         解决办法一,修改php配置文件,来支持https

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

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

                             重启服务就可以了;

            Linux下的PHP,就必须安装openssl模块,安装好了以后就可以访了。

          解决办法二,你可以通过使用curl函数来替代file_get_contents函数,当然你的主机必须支持curl函数。

    <?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);
    ?>

  • 相关阅读:
    Oracle删除.dbf文件报错
    Java 7 新的 try-with-resources 语句,自动资源释放
    模式对话框提交form之后总是打开新的页面
    MyEclipse更改项目的发布目录
    IntelliJ IDEA 更换发布目录
    java.sql.SQLException: ORA-00942: 表或视图不存在
    编码那点事
    配置nginx实现windows/iis应用负载均衡
    MSMQ消息队列
    .NET 分布式技术比较
  • 原文地址:https://www.cnblogs.com/tommy-huang/p/4178700.html
Copyright © 2011-2022 走看看