irfan shafi irfan shafi - 1 year ago 180
HTTP Question

HTTP URL Connection Timeout

When I hit the following URL in browser it's working perfectly:

but when I try to hit the URL with the following java code it's not working:

try {
URL url = new URL(null, "", new;
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();


String urlParameters="UID=something&P=something=InfoText&G=96567771404&M=hello&L=E";
// Send post request
DataOutputStream wr = new DataOutputStream(con.getOutputStream());

int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
catch(Exception e) {
System.err.println("Error: "+e.getMessage());

Is there anything wrong in the code?

Answer Source

You are sending a HTTP url through HttpsURLConnection. So its making problem. just change your first 2 line. You will get the proper output.

URL url = new URL("");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download