I'm facing a problem that at the moment I do not know how to solve.
Being straightforward, I'm having trouble sending through a java application the data in json for a page in php. Basically, I have a page in php that receives the data through the POST method and created a class in java that sends this data via post. The problem is that in java I do not enter the "handle" that is requested in the php page. As you can see, I get the value in the page in php by the filter_input(INPUT_POST, "user")
code snippet, except that in the java application I do not enter this "user" identifier in the information I want to send. So, there's no way the php page "picks up" the value that the java application is sending.
Anyone have any ideas how to solve this problem? Thank you very much in advance!
Home
PHP Page:
<?php
require_once './vendor/autoload.php';
$controller = new App\CWS\Controller();
if($_SERVER['REQUEST_METHOD'] == "POST"){
$controller->cadastrarUsuario(filter_input(INPUT_POST, "user"));
}
?>
Class responsible for connecting and submitting data in the Java application:
public class WebClient {
public String post(String json) {
try {
URL url = new URL("http://localhost//CWS//cadastrar_usuario.php");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setDoOutput(true);
PrintStream output = new PrintStream(connection.getOutputStream());
output.println(json);
connection.connect();
Scanner scanner = new Scanner(connection.getInputStream());
String resposta = scanner.next();
return resposta;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}