PHP用CURL发送Content-type为application/json的HTTP/HTTPS请求

<?php

$headers = array(

  "Content-type: application/json;charset=‘utf-8‘", 

  "Accept: application/json", 
  "Cache-Control: no-cache", 
  "Pragma: no-cache", 
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //设置超时
$url = ‘这里为请求地址‘;
if(0 === strpos(strtolower($url), ‘https‘)) {
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //对认证证书来源的检查
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //从证书中检查SSL加密算法是否存在
}
curl_setopt($ch, CURLOPT_POST, TRUE);
$data = array(0=>1,1=>2);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
$rtn = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
curl_close($ch);

PHP用CURL发送Content-type为application/json的HTTP/HTTPS请求,布布扣,bubuko.com

PHP用CURL发送Content-type为application/json的HTTP/HTTPS请求

上一篇:1-14编写一个程序,打印输入中各个字符出现频度的直方图


下一篇:20220202--CTF刷题MISC方向--第8题--十六进制转化成ASCII