i got this error when post json data using cURL , error message :Failed to connect to localhost port 8080: Connection refused
$session = $this->authentication->getAuth();
// JSON DATA
$json_data = json_encode($response_data);
// POST DATA USING CURL
$curl = curl_init();
$username = $session['id'];
$password = $session['name'];
$auth = base64_encode("$username:$password");
curl_setopt_array($curl, array(
CURLOPT_URL => "http://localhost:8080/api/store_book/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => 'gzip',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $json_data, // Only send JSON data
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Basic ' . $auth
),
));
$response = curl_exec($curl);
if(curl_errno($curl)) {
echo 'API Error: ' . curl_error($curl);
} else {
echo $response;
}