php curl模拟post提交数据示例

2025-05-29 0 82

复制代码 代码如下:


<?
header("Content-type: text/html; charset=utf8");
/*
* 提交请求
* @param $header array 需要配置的域名等header设置 array("Host: devzc.com");
* @param $data string 需要提交的数据 'user=xxx&qq=xxx&id=xxx&post=xxx'….
* @param $url string 要提交的url 'http://192.168.1.12/xxx/xxx/api/';
*/
function curl_post($header,$data,$url)
{
$ch = curl_init();
$res= curl_setopt ($ch, CURLOPT_URL,$url);
var_dump($res);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result = curl_exec ($ch);
curl_close($ch);
if ($result == NULL) {
return 0;
}
return $result;
}

$url = 'http://127.0.0.1' ;

$header = array("Host:127.0.0.1",
"Content-Type:application/x-www-form-urlencoded",
'Referer:http://127.0.0.1/toolindex.xhtml',
'User-Agent: Mozilla/4.0 (compatible; MSIE .0; Windows NT 6.1; Trident/4.0; SLCC2;)');


$data = 'tools_id=1&env=gamma';
echo "argv:$data<br>";

$ret = curl_post($header, $data,$url);
$utf8 = iconv('GB2312', 'UTF-8//IGNORE', $ret);
echo 'return:<br>'.nl2br($utf8 ).'<br>';
?>

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 php curl模拟post提交数据示例 https://www.kuaiidc.com/105741.html

相关文章

发表评论
暂无评论