phpamazon-ec2get-methodhttp-request2

HTTP_Request2 GET error


I am trying to connect to my Amazon EC2 website from my PHP server hosted on Godaddy. So using HTTP_Request2, I use the following:

$request = new HTTP_Request2('http://XX.XX.XXX.XXX:3007/something/something', HTTP_Request2::METHOD_GET);

This returns the following:

Error: Unable to connect to tcp://XX.XX.XXX.XXX:3007. Error: Connection refused

Now I know the port on my Amazon server is open and works when using jQuery to connect to it from my own machine or even my Godaddy website. However when trying to do the same thing except with PHP, it isn't working. I have made sure that I have installed request2 package on my Godaddy server.


Solution

  • Found out the problem. The problem is GoDaddy doesn't allow using custom ports (such as 3007 port I was trying to use) with curl or request2. A workaround to use on another server you are trying to connect to (if you manage/own that server):

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
    

    was posted at https://stackoverflow.com/a/16573737/4553140