Remote requests return 404 error when trying to get data from my local API

Hi community,

I’ve been strugling with something for the past weeks. When I execute a remote request from my local site (http://my-website.local) to my local API (http://jpanel.local/api/items/) using:

wp_remote_get( 'http://jpanel.local/api/items/' )

The response is a 404 status code, the weird thing is that 404 response is from my local site instead of my local API.

My local API is under WAMP server using Apache virtual server.

If I execute a remote request to my production API, works perfect. So, it looks like is trying to execute that request in the same domain.

I’ve been thinking about my IP address that somehow is conflicting each other.

Does anyone know what could it be and fix it? Thank you.

@roelmagdaleno

My thought is that in this case the Local site can’t see jpanel.local within the virtual environment due to the VM/container not using your main /etc/hosts file.

Also, 127.0.0.1 in the site container won’t reference your WAMP install so you’ll need to get the IP that routes from Docker to your host IP (your physical computer). See IP of HOST available within site container? for details on how to get that particular IP.

Once you have that IP, I recommend changing your wp_remote_get call to use the IP from above rather than jpanel.local.

Let us know how that works for you…

@andypeters

Thank you for giving me an idea, but I couldn’t do what you mentioned on Windows.

What I could do was install ngrok and execute it to obtain a public domain:

ngrok http -host-header=jpanel.local 80

Got the domain and use it into my wp_remote_get( 'ngrok.io/api/...' ) function.

Thanks! :slight_smile: