I am trying to pass a value from java class to PHP file on the server to test this value and reply to java. The problem it returns null value.
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); // print the string 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";
}
?>
Try the URL and URLConnection classes
Otherwise, your PHP looks OK.