How can I execute a PHP script from Java?

后端 未结 6 373
迷失自我
迷失自我 2020-12-16 03:01

I have a php script which is executed over a URL. (e.g. www.something.com/myscript?param=xy)

When this script is executed in a browser it gives a coded result, a neg

6条回答
  •  -上瘾入骨i
    2020-12-16 03:44

    public class URLConnectionReader {
        public static void main(String[] args) throws Exception {
            URL yahoo = new URL("http://www.yahoo.com/");
            URLConnection yc = yahoo.openConnection();
            BufferedReader in = new BufferedReader(
                                    new InputStreamReader(
                                    yc.getInputStream()));
            String inputLine;
    
            while ((inputLine = in.readLine()) != null) 
                System.out.println(inputLine);
            in.close();
        }
    }
    

    This snippet is from the offical Java tutorial (http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html). This should help you.

提交回复
热议问题