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

NoLAstNamE's avatar

HTTP request doesn't work on own domain

Server: Forge (DigitalOcean)

Laravel 9.33 - PHP 8.1

I'm trying to make an HTTP request to my own domain but I am getting null.

I'm currently working with this package mewebstudio/captcha to generate a captcha and yeah it's working fine on my localhost but NOT in production.

Is there any special thing to do with Forge to make it work?

$captcha = Http::get(url('captcha/api/math'));
dd($captcha->json());

// dd result
array:3 [▼
  "sensitive" => false
  "key" => "eyJpdiI6IjV6UytoNkd3WGJaUW9FcWU1STlkSWc9PSIsInZhbHVlIjoiZ2ZFVWNOOHZEOUwvT1Z0aFhKbDFyUHhjekh3YVFGZ2lyRmdwN1VXWlNvblc5U3AzUkFXS1BkQ0VRY0QyQVVJdDJsaTdQVHg1VVZBWU5C ▶"
  "img" => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAuCAYAAADKmOD6AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAgAElEQVR4nKV9e7BlVXnnb++99t7n7PO45z67+3b37feTR0sjCASRJMokDk6mEk ▶"
]

EDIT:

I tried to make a GET request in PostMan and it's working there.

URL: https://site.com/captcha/api/math

0 likes
3 replies
NoLAstNamE's avatar

Update:

I've got a workaround but I'm not sure if this has a security flaw. I've added acceptJson and allow Access-Control-Allow-Origin

$captcha = Http::acceptJson()->withHeaders([
    'Access-Control-Allow-Origin' => '*'
])->get(url('/captcha/api/math'));
NoLAstNamE's avatar

@Sinnbeck I tried that one from here, but there is a problem, I can type whatever I want in the textbox and it always says correct.

The one that I'm currently using is the Stateless mode - here, the captcha validation is working fine.

Please or to participate in this conversation.