Subscribe to the blog

Social networks

My page on
My page on Facebook
My page on Google plus
My page on Twitter

Main - Blog - Post java - Send POST request in Java

Programming Date of creation: Views: 378

Post java - Send POST request in Java


Send POST request to java

Below, the post-request code for the java application is placed
package postjava;
public class PostJava {
    public static void main(String[] args) throws Exception {
        String url = "";              
        String param = "text=hello world!";
        URL url_post_java = new URL(url);
        HttpsURLConnection Post_Java = (HttpsURLConnection) url_post_java.openConnection();
        // Send post request
        DataOutputStream write_post = new DataOutputStream(Post_Java.getOutputStream());

POST request receiver in PHP

We create a file post.php, which in the future we place on hosting


$text = $_POST["text"];

$fd = fopen("post.txt", 'w') or die("не удалось создать файл");
$str = $text."\n;"
fwrite($fd, $str);

echo $str;

<form method="post">
    <input  name="text"  value="">
    <input type="submit" name="submit"></input>

And also, it is necessary in advance to create a file post.txt, which will be in the same folder on the server as post.php

This post.php file will accept the send request from the Java application, and in order for us to see that the request was sent the data will be written to the post.txt file

After the query is executed in the Java application, you need to open the text document post.txt

Post java - Send POST request in Java
Rating: 5 | Тotal votes: 1 | Please, rate this article


    Subscribe to the blog

    Random articles from the blog:

    Generator Binary code online

    Generator Binary code online
    Topic: Programming

    Tags: binary code, online resource,generator


    How to send email to JSP Java

    How to send email to JSP Java
    Topic: Programming

    Tags: java,jsp,send email,email


    Installing Apache Tomcat to work in Java JSP

    Installing Apache Tomcat to work in Java JSP
    Topic: Programming

    Tags: java,jsp,сервер,apache tomcat