0

To API Java code with PHP, and connect a Java frontend with a PHP backend that will connect to a database, you just call the PHP file's URL in the code, correct?

URL url = new URL("http://10.0.3.2/MYCODE/app/login.php");

String urlParams = "name="+name+"&password="+password;

HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
OutputStream os = httpURLConnection.getOutputStream();
os.write(urlParams.getBytes());
os.flush();
os.close();

1 Answer 1

1
public String login(String name ,String password) {
StringBuilder sURL = new StringBuilder(100);
        StringBuilder sb1 = new StringBuilder();
        System.out.println("FF:"+pathReader);
        try {
            sURL.append("http://10.0.3.2/MYCODE/app/login.php?");
            sURL.append("name="+name);
            sURL.append("&password="+password);
            InputStream is = new URL(sURL.toString()).openStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
            int cp;
            while ((cp = rd.read()) != -1) {
                sb1.append((char) cp);
            }

            }
        catch (Exception me) {
            System.out.println("## Exception :" + me.getMessage());
        }
        sb1.toString();
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.