I am trying to transfer a value from a java class to a PHP file on the server in order to check this value and respond to java. The problem returns null.
Java code
package phpJava;
import java.io.*;
import java.net.URL;
import javax.swing.JOptionPane;
public class phpbirgde {
public static void main(String[] args) {
try{
String erg = JOptionPane.showInputDialog("2+3");
BufferedReader br = new BufferedReader(new InputStreamReader(new URL("http://localhost//test.php?test="+erg).openStream()));
String b = br.readLine();
System.out.println(b);
if(b.equalsIgnoreCase("true")){
System.out.println("It is true");
}
else {
System.out.println("False");
}
} catch(IOException e){
System.out.println("error");
}
}
}
PHP code
<?php
$test = $_GET['test'];
if($test =="5"){
echo "true";
}
else {
echo "false";
}
?>
source
share