I'm trying to create a client server application and I'm currently stuck. I have this java code on my client.
HttpURLConnection connection;
connection = (HttpURLConnection) new URL("http://www.masterpaint.gr/login.php").openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-Type","application/json; charset=UTF-8");
connection.setRequestProperty("Accept","application/json: charset=UTF-8");
connection.setRequestMethod("POST");
System.out.println("The request method on client end is " + connection.getRequestMethod());
System.out.println("Server response to connection " + connection.getResponseMessage());
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String buffer;
StringBuilder stringBuilder = new StringBuilder();
while ((buffer = reader.readLine()) != null) {
stringBuilder.append(buffer);
}
System.out.println("The request methond on server end is " + stringBuilder.toString());
And this is the simple test php code on the server.
<?php echo $_SERVER['REQUEST_METHOD']; ?>
Whenever I run this test java program and try to connect I get the same output.
The request method on client end is POST
Server response to connection OK
The request methond on server end is GET
The php script always echoes back that I'm sending a GET request even though
my java code states that use a POST. I have tried connecting to the script through postman using different request methods and it's all fine, so the problem must be in the Java code. Any insight would be greatly appreciated.