将变量从java应用程序发布到PHP

时间:2016-12-13 16:34:29

标签: java php post

我正在使用Netbeans构建一个java应用程序,我想创建一个JButton来将我的应用程序中的值发布到php文件中。 我正在应用以下代码,但它无法正常工作:

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         

 try{
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://localhost/blow.php/");

List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("date", "12/11/2016"));

httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

//Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();

if (entity != null) {
    InputStream instream = entity.getContent();
    try {
        // do something useful
    } finally {
        instream.close();
    }
}
        }catch(Exception w){
            System.err.println(w);}
// open file location and check 
String FolderName="http:\\localhost/blow.php";//Write your complete path here
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + FolderName);
    } catch (IOException ex) {
          Logger.getLogger(blowing.class.getName()).log(Level.SEVERE, null, ex);
    }      


    }

并且在php文件中只写了:

 <?php

   $da=$_POST['date'];
   echo $da;

 ?>

请帮助解决这个问题,谢谢

0 个答案:

没有答案