$data_str = json_encode($data);
$ch = curl_init($url); //初始化curl
curl_setopt($ch, CURLOPT_MAXREDIRS, 20); //页面跳转次数
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且不输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式---
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10); // 在尝试连接时等待的秒数
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str); //提交数据
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Origin:http://' . $_SERVER['SERVER_NAME'], //模拟浏览器CORS跨域请求
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data_str))
);
$contents = curl_exec($ch);
curl_close($ch);
PHP curl添加头信息(Origin:)
最新推荐文章于 2022-12-27 15:12:44 发布