php语言

PHP基于CURL进行POST数据上传实例

时间:2024-10-22 13:45:35 php语言 我要投稿
  • 相关推荐

PHP基于CURL进行POST数据上传实例

  PHP 是一种 HTML 内嵌式的语言,是一种在服务器端执行的嵌入HTML文档的脚本语言,语言的风格有类似于C语言,被广泛地运用。以下是小编为大家搜索整理的PHP基于CURL进行POST数据上传实例, 希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网!

  ////二维码

  $QRCode_URL="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$ACC_TOKEN;

  $data ='{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 123}}} ';

  /*

  $ch = curl_init($MENU_URL);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length:'.strlen($data)));

  $info = curl_exec($ch);

  */

  function post($url, $params = false, $header = array()){

  $ch = curl_init();

  $cookieFile = 'sdadsd_cookiejar.txt';

  curl_setopt($ch, CURLOPT_POST, 1);

  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);

  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, 30);

  if($params !== false){ curl_setopt($ch, CURLOPT_POSTFIELDS , $params);}

  curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0');

  curl_setopt($ch, CURLOPT_URL,$url);

  curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

  $result = curl_exec($ch);

  curl_close($ch);

  return $result;

  }

  $result = post($QRCode_URL,$data);

【PHP基于CURL进行POST数据上传实例】相关文章:

PHP基于CURL进行POST数据上传的方法06-19

PHP如何用curl发送GET和POST请求09-07

PHP如何使用curl发送GET和POST请求09-10

PHP中使用cURL实现Get和Post请求的方法10-30

PHP如何使用curl实现数据抓取09-27

php的curl学习总结07-08

php获取新浪微博数据API的实例代码08-06

PHP socket的配置及实例10-16

php查询mysql的实例09-09

PHP中用CURL伪造IP来源的方法06-26