Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpClient give Connection refused

807605Sep 14 2007 — edited Sep 14 2007
Hi all,

I have a class in which i am using httpClient to Post a request to server which responds back with a XML. But the problem which i am facing is that if i mention name of sever as dns name(eg. xyx.abc.yy.com:61002) i get the connection refused error while if i use IP in place of dns (eg. 1.2.3.4:61002) it works fine.

I have double checked with the DNS name dns is being properly resolved to IPs and same URL is being used by another components and it is working fine with DNS. Network Analysis team told me that if i use DNS request hits port 80 while if i use IP it hits the desired port.
Please help me with the suggestions.
Following is the code which i am using for this class:-
public class HttpClientTutorial implements HttpConnectionManager {

private static String url = "http://abc.def.ghk.com:61002/something";

public static void main(String[] args) {
// Create an instance of HttpClient.

HttpClient client = new HttpClient();

// Create a method instance.
PostMethod method = new PostMethod(url);
method.setParameter("name", "value");
// Provide custom retry handler is necessary

method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));

try {
// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
byte[] responseBody = method.getResponseBody();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));

} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
}


Regards
Neoms21
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 12 2007
Added on Sep 14 2007
1 comment
1,828 views