C
Camel
Hi all,
I have an application that uses a communication Thread that opens a
connection to a server(router's web server) every few seconds. I'm using a
simple http protocol. Below is the piece of code:
------code begin--------
......
URL gatewayURL;
HttpURLConnection gc = null;
DataOutputStream dos = null;
String gatewayStr = http://192.168.0.1/cgi-bin/webcm;
String query = URLEncoder.encode("logic:command/save","UTF-8");
query += "=";
query += URLEncoder.encode("","UTF-8");
try {
gatewayURL = new URL(gatewayStr);
gc = (HttpURLConnection)gatewayURL.openConnection();
gc.setDoOutput(true);
gc.setDoInput(true);
gc.setAllowUserInteraction(false);
gc.setUseCaches(false);
gc.setRequestMethod("POST");
gc.connect();
dos = new DataOutputStream(gc.getOutputStream());
dos.writeBytes(query);
dos.flush();
int code = gc.getResponseCode();
String message = gc.getResponseMessage();
System.out.println(gc.getURL());
System.out.println(code + " " + message);
dos.close();
gc.disconnect();
}catch (Exception e) {}
......
------code end------
The problem is: sometimes the program stops at gc.getResponseCode() line. No
exception cought. Nothing, it just stops at there.
What could be the problem?
Thank you all in advance.
I have an application that uses a communication Thread that opens a
connection to a server(router's web server) every few seconds. I'm using a
simple http protocol. Below is the piece of code:
------code begin--------
......
URL gatewayURL;
HttpURLConnection gc = null;
DataOutputStream dos = null;
String gatewayStr = http://192.168.0.1/cgi-bin/webcm;
String query = URLEncoder.encode("logic:command/save","UTF-8");
query += "=";
query += URLEncoder.encode("","UTF-8");
try {
gatewayURL = new URL(gatewayStr);
gc = (HttpURLConnection)gatewayURL.openConnection();
gc.setDoOutput(true);
gc.setDoInput(true);
gc.setAllowUserInteraction(false);
gc.setUseCaches(false);
gc.setRequestMethod("POST");
gc.connect();
dos = new DataOutputStream(gc.getOutputStream());
dos.writeBytes(query);
dos.flush();
int code = gc.getResponseCode();
String message = gc.getResponseMessage();
System.out.println(gc.getURL());
System.out.println(code + " " + message);
dos.close();
gc.disconnect();
}catch (Exception e) {}
......
------code end------
The problem is: sometimes the program stops at gc.getResponseCode() line. No
exception cought. Nothing, it just stops at there.
What could be the problem?
Thank you all in advance.