Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JAVA中点击URL而不重定向_Java_Php_Redirect - Fatal编程技术网

在JAVA中点击URL而不重定向

在JAVA中点击URL而不重定向,java,php,redirect,Java,Php,Redirect,我想从java servlet点击php中的一个URL。我只想向该URL发送一个信息。我不需要转到该URL。我想留在我的页面中。无论如何,要做到这一点。?你只需像在http组件中一样在该URL上发表文章即可 尝试以下代码 URL url = new URL("your url"); URLConnection connection = url.openConnection(); connection.setConnectT

我想从java servlet点击php中的一个URL。我只想向该URL发送一个信息。我不需要转到该URL。我想留在我的页面中。无论如何,要做到这一点。?

你只需像在http组件中一样在该URL上发表文章即可


尝试以下代码

            URL url = new URL("your url");

            URLConnection connection = url.openConnection();
            connection.setConnectTimeout(5000); // time out
            connection.setDoOutput(true);
            PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream()));
            String postData = "your post data";
            out.print(postData);
            out.close();
            String response  connection.getInputStream();
或者你可以使用

           Request.Post("your url").bodyForm(
                Form.form().add("parameter name", "value")
                .add("parameter name1", "value").build()).execute();

也许是http组件?Apache Http客户端已经在版本4中。不建议使用版本3(但可以,它可以工作)。
           Request.Post("your url").bodyForm(
                Form.form().add("parameter name", "value")
                .add("parameter name1", "value").build()).execute();