Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1423
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2019-11-13 10:14
文章分类

全部博文(3)

文章存档

2019年(3)

我的朋友

分类: IT业界

2019-12-05 17:16:15

php如何发送http请求和实现https接口

1。输入接口:


贵妍美商城系统开发(T:/ I8O..2853..296O V黎),贵妍美面膜商城系统APP开发,贵妍美面膜商城系统软件开发,贵妍美面膜商城模式系统开发,贵妍美面膜商城系统源码开发,贵妍美面膜分销商城系统开发,贵妍美面膜推荐收益系统开发 URL/ spservice/downring.do? sid =1234 & sidpwd =123456& randomsessionkey =123420031212121212123456& modulecode=z1000XXX&opertype=1&tonecode=1234123412& issendsms =0& backurl=



2。如何发送http请求,最好有例子,谢谢!


 
PHP的文件操作函数几乎都能用来发送http请求:


$html = file_get_contents('');
var_dump($html);
有些网站会对请求头信息进行检测,这时候就需要用到curl了(php.ini中要启用curl扩展),贴一个我一直用的函数:


function fetch_page($site,$url,$params=false)
{
    $ch = curl_init();
    $cookieFile = $site . '_cookiejar.txt';
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
    curl_setopt($ch, CURLOPT_COOKIEFILE,$cookieFile);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch,   CURLOPT_SSL_VERIFYPEER,   FALSE);
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 4);
    if($params)
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
    curl_setopt($ch, CURLOPT_URL,$url);


    $result = curl_exec($ch);
    //file_put_contents('jobs.html',$result);
    return $result;
}
调用示例:


$html = fetch_page('google','','key=value');
var_dump($html);
如果请求类型是https,则只能用curl了,前者会报(至少默认情况下):


PHP Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?


如果你说的实现https接口指的是让别人可以用https访问你,那么就需要用openssl生成公私钥,然后编译apache使支持mod_ssl,然后再配置httpd-ssl.conf文件,这些让系统管理员来做吧。。
阅读(206) | 评论(0) | 转发(0) |
0

上一篇:众享礼APP开发案例

下一篇:没有了

给主人留下些什么吧!~~