Unable to make API calls .. getting the error “Could not connect to http:///myapi”

I am unable to make any API calls. When I make the API calls via the UI, I am getting the following error:

Error Sending Request

Could not connect to http://<hostalias>/myapi. Make sure the URL is correct.

Can you please help in fixing this error ?

Solved Solved
0 1 3,135
1 ACCEPTED SOLUTION

  • Executed the API calls using https (secure call), boom - it worked
  • Logged onto one the routers and used the netstat utility to check on what http/https ports are we listening
netstat -lnt
  • The output came up like this:
 Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 127.0.0.1:9001                0.0.0.0:*                   LISTEN

tcp        0      0 <Internal IP address>:9001                 0.0.0.0:*                   LISTEN

tcp        0      0 127.0.0.1:443              0.0.0.0:*                   LISTEN

tcp        0      0 <Internal IP address>:443                 0.0.0.0:*                   LISTEN

tcp        0      0 <External IP address>:443                 0.0.0.0:*                   LISTEN
  • The above output showed that the router was listening on the port 9001 (default virtual host) for the internal IP address, but not on the external IP address
  • Also, noted that router is listening on port 443 (secure virtual host) for internal and external IP address, so the secure calls were going through fine outside of the routers well
  • Next, I tried to make the API call using the router’s internal and external IP addresses with port 9001 as shown below:
curl -v http://<Router's IP address>:9001/myapi -H "Host: <hostalias>"
  • It worked fine with the internal IP address, it worked
  • However, the API call failed as expected with the external IP address
  • This confirmed that the cause of this issue was that the router was not listening on the external IP address on the default virtual host port
  • I also verified that the same was the case in the other router

Enabling the routers to listen on the port # 9001 for external IP address resolved the issue.

View solution in original post

1 REPLY 1

  • Executed the API calls using https (secure call), boom - it worked
  • Logged onto one the routers and used the netstat utility to check on what http/https ports are we listening
netstat -lnt
  • The output came up like this:
 Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 127.0.0.1:9001                0.0.0.0:*                   LISTEN

tcp        0      0 <Internal IP address>:9001                 0.0.0.0:*                   LISTEN

tcp        0      0 127.0.0.1:443              0.0.0.0:*                   LISTEN

tcp        0      0 <Internal IP address>:443                 0.0.0.0:*                   LISTEN

tcp        0      0 <External IP address>:443                 0.0.0.0:*                   LISTEN
  • The above output showed that the router was listening on the port 9001 (default virtual host) for the internal IP address, but not on the external IP address
  • Also, noted that router is listening on port 443 (secure virtual host) for internal and external IP address, so the secure calls were going through fine outside of the routers well
  • Next, I tried to make the API call using the router’s internal and external IP addresses with port 9001 as shown below:
curl -v http://<Router's IP address>:9001/myapi -H "Host: <hostalias>"
  • It worked fine with the internal IP address, it worked
  • However, the API call failed as expected with the external IP address
  • This confirmed that the cause of this issue was that the router was not listening on the external IP address on the default virtual host port
  • I also verified that the same was the case in the other router

Enabling the routers to listen on the port # 9001 for external IP address resolved the issue.