After migration to Cake 4.2 $this->request->host(); in component not working

In my component I would like to know the host on which the application is running.
In Cake 3.9 the statement “$host = $this->request->host();” worked fine.
Now, in Cake 4.2, I get the error message “Call to a member function host() on null”.
Thanks for giving me an idea what to do.

Did you run your version 3.9 application with deprecation notices enabled? Getting it to run like that without any warnings should be the first step in upgrading to 4.x.

Yes, the application in version 3.9 run with deprecation notices enabled and everything was ok.
In version 4.2 the statmeent “$host = $this->request->host();” works fine in the AppController, but not in the component. It looks like loosing the object in the component.
I have no idea what to try. Thanks for any help.

please try this one into component

This works fine. Thank you very much!