In my case, I had ocs server and client installed on the same box, AND I configured an external http proxy server to access the internet.
Just anything used the proxy, including the ocs inventory agent, and that was the reason it couldn't access http://localhost/ocsinventory/
TLDR; just
# unset http_proxy
# unset https_proxy
# /usr/local/bin/ocsinventory-agent --debug
Mauro