I am developing an application for android and this makes a POST request sending some values to a television decoder. The application generates the values correctly but at the time of sending the data to the device it gives several errors among which are timeout, no route to host, and some similar. I have made sure that I can access from the phone's browser to the ip and write the url well and sometimes it goes and others do not.
I use a python script to create a server and to show me the request made by the application to see that there are no errors in the parameters but what I have noticed is that the request takes time to complete. That is, the application connects to the server, sends the header containing the host, the user-agent, and other data ... but does not send the parameters until after a few seconds (10-15s) or until I close the application.
I have tried increasing the connectionTimeout but no matter how long I put it, it gives me the same error. It seems that it is connection but it happens to many people that I have passed the app to try it with its decoder. Some went well, to others it gives connection problems such as the error of no route to host or connection timeout , but the system has been damaged due to the need to reinstall the firmware using an RS232 cable. In theory I'm just passing the data to a decoder page and should not fail to such a point, but if the request is halfway if it could get caught the server does not?
Well I leave you the code I use to make the POST request and I hope you can help me out.
public PostTwo(String url, String params) throws IOException {
try {
URL url1 = new URL("http://"+url);
HttpURLConnection client = (HttpURLConnection)url1.openConnection();
client.setRequestMethod("POST");
client.setConnectTimeout(10000);
//client.setRequestProperty("arg1","valor");
client.setDoOutput(true);
client.setFixedLengthStreamingMode(params.getBytes().length);
//client.setChunkedStreamingMode(0);
OutputStream outputPost = new BufferedOutputStream(client.getOutputStream());
outputPost.write(params.getBytes());
outputPost.flush();
outputPost.close();
client.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}