一起源码网

  • www.171739.xyz
  • 全球最大的互联网技术和资源下载平台
搜索
猜你喜欢
查看: 4491|回复: 1
打印 上一主题 下一主题

PHP功能强大的CURL POST类

[复制链接]

0

主题

0

帖子

1万

积分

钻石会员

Rank: 8Rank: 8

积分
17424
QQ
跳转到指定楼层
楼主
发表于 2020-5-23 12:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本文主要为大家详细介绍了功能强大的PHP POST提交数据类,代码简洁且具有一定的参考价值,感兴趣的小伙伴们可以参考一下。希望对大家有所帮助。

具体内容如下

<?php 
class Request{
  public static function post($url, $post_data = '', $timeout = 5){//curl

    $ch = curl_init();
 curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, 1);
    if($post_data != ''){


      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

    }
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HEADER, false);
 $file_contents = curl_exec($ch);
    curl_close($ch);
    return $file_contents;

  }

  public static function post2($url, $data){//file_get_content
    $postdata = http_build_query(
      $data
    );
    $opts = array('http' =>
           array(
             'method' => 'POST',
             'header' => 'Content-type: application/x-www-form-urlencoded',
             'content' => $postdata
           )

    );

    $context = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);
    return $result;

  }
 public static function post3($host,$path,$query,$others=''){//fsocket

    $post="POST $path HTTP/1.1
Host: $host
";
    $post.="Content-type: application/x-www-form-";
    $post.="urlencoded
${others}";
    $post.="User-Agent: Mozilla 4.0
Content-length: ";
    $post.=strlen($query)."
Connection: close

$query";
    $h=fsockopen($host,80);
    fwrite($h,$post);
    for($a=0,$r='';!$a;){
        $b=fread($h,8192); 
        $r.=$b;
        $a=(($b=='')?1:0); 

      }
    fclose($h);
    return $r;

  }

}

?>

分享到:  QQ好友和群QQ好友和群
收藏收藏
回复

使用道具 举报

0

主题

18

帖子

56

积分

注册会员

Rank: 2

积分
56
沙发
发表于 2022-10-12 07:50 来自手机 | 只看该作者
代码下载全网音乐
回复

使用道具 举报

一起源码让程序更轻更快

www.171739.xyz

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表