How can I execute a PHP script from Java?

后端 未结 6 375
迷失自我
迷失自我 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条回答
  •  失恋的感觉
    2020-12-16 03:53

    If you are trying to run it over HTTP I would recommend the Apache Commons HTTP Client libraries. They make it incredibly easy to perform this type of task. For example:

        HttpClient http = new HttpClient();
        http.setParams(new HttpClientParams());
        http.setState(new HttpState());
    
        //For Get
        GetMethod get = new GetMethod("http://www.something.com/myscript?param="+paramVar);
        http.executeMethod(get);
    
        // For Post
        PostMethod post = new PostMethod("http://www.something.com/myscript");
        post.addParameter("param", paramVar);
        http.executeMethod(post);
    

提交回复
热议问题