Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kaustubh's avatar

Curl Response Blank in Laravel

Hi

I am getting empty curl response in laravel but when i tried in postman i am getting valid response. Here is my code

$ch = curl_init();
$url = "http:/localhost/project/public/api/api_jobpost";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
CURLOPT_HTTPHEADER => array(
    "Authorization: ".$headers['authorization'],
    "Cache-Control: no-cache",
    "Content-Type: application/json",
    $headers['date']
),
curl_setopt($ch, CURLOPT_POSTFIELDS, 'Job_pos_id=' . $job_pos_id . '&Job_loc=' . $job_loc . '&Job_type=' . $job_type . '&Job_title=' . $job_title . '&Datetimepicker1=' . $starts . '&Datepicker2=' .$end. '&start=' .$start. '&length=' .$limit);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$server_output = curl_exec($ch);

if (curl_error($ch)) {
    $error_msg = curl_error($ch);
    return Response::json(['msg' => 'Something Went Wrong'], 500);
}
curl_close($ch);

print_r($server_output);
exit();
0 likes
2 replies
bobbybouwmann's avatar

Your URL is incorrect at the http:// part

// This
http:/localhost/project/public/api/api_jobpost

Should be this
http://localhost/project/public/api/api_jobpost
Kaustubh's avatar

Thnx buddy

But i found the real issue.

I have 2 laravel projects, I am calling api of project 2 in project 1. So when i call api it throws table not found exception in project 2, because it uses project 1 database connection in project 2. I dont know why it uses project 1 connection in project 2 even they are different projects

Please or to participate in this conversation.