title: post a request from java to php
body: <p>I have a problem ,when I send a post request from java to web server .But when I use GET method it works very well .</p>
  
  <p>java code </p>
  
  <pre><code>   package networkTest;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.nio.charset.Charset;
  
  public class Main {
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      try {
          URL url=new URL("http://127.0.0.1/index.php");
          HttpURLConnection curl=(HttpURLConnection) url.openConnection();
          curl.setDoInput(true);
          curl.setDoOutput(true);
          curl.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
          curl.setAllowUserInteraction(true);
  
          curl.setRequestMethod("POST"); //**
          OutputStream out =curl.getOutputStream();
          InputStream in =curl.getInputStream();
          String data="name=xxx";
          out.write(data.getBytes());
  
          InputStreamReader reader=new InputStreamReader(in);
          BufferedReader Breader=new BufferedReader(reader);
          String buff;
          String Rdata="";
          while((buff=Breader.readLine()) !=null )
          {
              Rdata+=buff+"\n";
          }
          System.out.println(Rdata);
  
  
  
  
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          System.err.println("error in url connection");
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          System.err.println("IO execption: error in opening connection");
          e.printStackTrace();
      }
  
  
  
    }
  }
  </code></pre>
  
  <p>PHP code 
  I received a response from <code>inputstream</code> but the $_POST["name"] is always unset and the response is always "there is no request " </p>
  
  <pre><code>&lt;?php
      if(isset($_POST["name"]))
      {
          echo($_POST["name"]);
      }
      else
      {
          echo"there is no request";
      }
  ?&gt;
  </code></pre>