PHP Curl Post示例
<?php
// 返回JSON
header("Content-type:application/json");
// 初始化 CURL
$ch = curl_init();
// 服务器URL
curl_setopt($ch, CURLOPT_URL,'服务器URL');
curl_setopt($ch, CURLOPT_POST, true);
// 设置参数
$data = array(
array(
'aaa' => 'aaa',
'bbb' => 'bbb'
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// 获取的信息以文件流的形式返回,而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 请求头
$headers[] = "content-type:multipart/form-data;"; // content-type
$headers[] = "user-agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3947.100 Safari/537.36"; // user-agent
$headers[] = "cookie:xxx"; // cookie
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
// 发起请求并返回请求结果
$result = curl_exec($ch);
// 关闭请求
curl_close($ch);
?>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!