Manish Mudgal
Manish Mudgal

Reputation: 1186

java - can't make http request on port other than 80

My java program is hitting "http://url:port" kind of url to fetch some data. On my local windows machine deployed on tomcat 6, it is working fine. But on production which is a linux machine having tomcat 6 on it, it gives me connection timeout.

Ironically, if I hit the URL without port number, it will successfully bring me the output but not with port. Not finding any clue, please help.

The snippet of code I am using to connect and fetch data is:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("59.162.167.36:80/api/…");
httpget.setHeader("User-Agent", "UserAgent: Mozilla/5.0");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();

Upvotes: 2

Views: 3793

Answers (3)

Richard H
Richard H

Reputation: 39055

Almost certainly your hosting provider implements a firewall of some description in the data center. This is common practice. Send them a message asking if port X is blocked, and if so can they open it.

Upvotes: 1

Giuseppe Di Federico
Giuseppe Di Federico

Reputation: 3589

The answer is straightforward: On production you don't have that port opened, contact the administrator, or the hosting and issue your problem. Of course they will confirm my thesis.

Upvotes: 1

President James K. Polk
President James K. Polk

Reputation: 41958

One obvious possibility is that a firewall in front of your production machine is blocking access to that port. Check the firewall.

Upvotes: 4

Related Questions