欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-12-23 22:33:00
本文实例讲述了php基于curl进行post数据上传的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下: ////二维码 $qrcode_url="...

本文实例讲述了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程序设计有所帮助。