I am building a java application using Netbeans, I want to create a JButton to post a value from my application to a php file. I am applying the following code and it is not working:
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);
}
}
and in the php file only this is written:
<?php
$da=$_POST['date'];
echo $da;
?>
Can you help with this please, thanks