Curl not working in homestead

Posted 1 year ago by eddieace

For some reason, I can't use CURL to send post requests in homestead. It just returns null and here is my code.

Additional, headers are not being set, even if it's application/json it returns HTML/charset.

any clues?


            $ch = curl_init(env('app_url') . 'applications/' . $position->ats_reference . '/import');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
                'token' => $user->token,
                'data' => [$data]
            ]));
            curl_exec($ch);
            $info = curl_getinfo($ch);
            dd($info);
            curl_close($ch);

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.