原文:http://blog.csdn.net/tracywxh/article/details/8745595
1、下面为模拟提交文件 2.
- /**
- *
- * @param $url
- * @param $data
- * @param $method
- */
- function curlrequest($url,$data,$method='post'){
- $ch = curl_init(); //初始化CURL句柄
- curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式
- curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-HTTP-Method-Override: $method"));//设置HTTP头信息
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
- $document = curl_exec($ch);//执行预定义的CURL
- curl_close($ch);
- return $document;
- }
- $url = 'www.wxh.com/3.php';
- $data = "m=1&c=2&jaingxi=67";
- $return = curlrequest($url, $data, 'put');
- var_dump($return);
-
- <?php
- $_PUT = array();
- if ('put' == $_SERVER['REQUEST_METHOD']) {
- parse_str(file_get_contents('php://input'), $_PUT);
- var_dump($_PUT);
- }