3

I have java client application and I need to run a PHP script on server. That PHP scrips will create some word and excel files and than I want to download that created files on client's machine. Can I use somehow URL, but without opening a browser? And then download created files from server?

1 Answer 1

3
public class URLConnectionReader {
    public static void main(String[] argv) {
      try {
        URL phpUrl = new URL("http://server/myphp.php");
        URLConnection urlCon = phpUrl.openConnection();
        BufferedReader br = new BufferedReader(
                                new InputStreamReader(
                                urlCon.getInputStream()));
        String line;

        while ((line = br.readLine()) != null) 
            System.out.println(line);
        br.close();
      } catch(Exception e) {
        // handle errors here...
      }
    }
}

you will need to modify the php applicatin to receive some details about the results. Either the file location or maybe the file in MIME.

But you will need to add more information so we can help you out.

Sign up to request clarification or add additional context in comments.

1 Comment

you could use the apache http client with lots of good features for calling urls and mgmnt [link]hc.apache.org

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.