Hi,
I have a service I'm running in a docker container locally, listening in port 8000.
I'm trying to send a GET request from my apex code to the service and getting an 403 error.
The user has "API enabled", and the endpoint was added to the "Remote Sites".
When I try sending the same request from potman or the browser, I reach the service and get the required response.This is my code:
HttpRequest request = new HttpRequest();
request.setEndpoint('http://localhost:8000/ABRequest');
request.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(request);
System.debug(response.getStatusCode());
Can anyone help to understand what I'm missing?
Just to add some context here, Apex code is executed on the server side (Salesforce's servers). Localhost is an address in your private network, so it is not reachable from these servers.
On the other hand, if you do fetch calls from a LWC component, as the LWC code is executed on the client side, it can see localhost and perform the calls correctly.
To be able to call localhost, you need to first expose it to a public URL. You can achieve so with tools like ngrok.
You can check this post with more context.