CURL的使用

时间:2022-12-21 10:10:44
$headers = array(
    "TYPE:xxxxooooo",
    "TOKEN:00000000"
);

$data = array(
    'data' => array('name' => 'test','AGE'=>22),
    'registration_ids' => array('APA91bEyno5XgFPvIGxMezCsnaOXwmxbHXzxAJ6X_v2w0VPEFrUb24Mw9LdeTqpA6kHkaxrwHD8N_QsBpRduKll3K9qEe2EYIw1y_rqW9UNsU_X4NsnanTVjscPBBkWVkIOfDqff6QlQJOmvA1x2kAkloq0bgMHmDe_HoWKjh1IhoDHgJzw5L2c')
);

$url = "http://www.adtuu-server.com/curl-get.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST,count($data)) ;
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);
curl_close($ch);
var_dump($response);


$input = file_get_contents('php://input');
$input = json_decode($input, true);
var_dump($input);

var_dump($_SERVER);
var_dump($_SERVER['HTTP_TYPE']);
var_dump($_SERVER['HTTP_TOKEN']);