I am creating plugin and I need to get data using curl request. Here is my code
$userName = 'admin';
$password = '123456';
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => "https://apis.tcscourier.com/production/v1/cod/create-order",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "
{"userName":"<?php $userName ?>","password":"<?php $password ?>","costCenterCode":"2705","consigneeName":"Nabeel Khan"}
",
CURLOPT_HTTPHEADER => [
"X-IBM-Client-Id: 9b9fc7fa5fc4",
"accept: application/json",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
But the $username and $password variable in CURLOPT_POSTFIELDS is not working or output. So I want to know how to output variables in CURLOPT_POSTFIELDS ?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…