So for about an hour I have tried to get my java method to post to my webserver, but for some reason it refuses to. The get’s arrives just fine, but for some reason not the posts.
public static void refresh(){
LEDS[1].setState(LEDS[1].getState().equals(HIGH) ? LOW : HIGH);
final String data = "updatesPerSecond=" + Integer.valueOf(PinTest.processCountPerSecond);
final String URL = "http://127.0.0.1/light/index.php?"+data;
try{
HttpURLConnection conn = (HttpURLConnection)new URL(URL).openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty( "charset", "utf-8");
conn.setUseCaches(false);
conn.setDoOutput(true);
conn.setDoInput(true);
//Send data
try(DataOutputStream out = new DataOutputStream(conn.getOutputStream()); InputStream in = conn.getInputStream()){
//Send data
out.writeBytes(data);
out.flush();
//Read reply
int lenght;
byte[] buffer = new byte[1024];
while((lenght = in.read(buffer)) != -1){
in.read(buffer, 0, lenght);
}
}
}catch(Exception e){
LEDS[0].setState(HIGH);
}
}
I know the read does nothing, I just attempted everything I can think of.