How can I call a PHP script with parameters?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jacques_Marques
Posted On:   Friday, May 9, 2003 12:59 PM


I want call a PHP script with parameters within a console Java program, not a servlet or JSP.


Can any one help me?


Thanks

Re: How can I call a PHP script with parameters?

Posted By:   Yasir_Khan  
Posted On:   Tuesday, May 13, 2003 06:57 AM

I am writing here the code that connects to a PHP page and sends some prameters to the page as POST and then it prints the whole HTML response from PHP page to console, I hope following code will help:

try{
URL url = new URL("http://mywebsite:port/scripts/validate.php");
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
OutputStream os = urlConnection.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
String postString = "Name"+"="+"Yasir Khan"+
"&Email"+"="+"yasir.khan@ascertia.com";
dos.writeBytes(postString);
InputStream is = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line= null;
while( (line = br.readLine()) != null ){
System.out.println(line);
}
System.out.println("line "+line);
dos.close();
br.close();
urlConnection.disconnect();
}
catch(Exception ex) {
ex.printStackTrace();
}

Regards,

YK
About | Sitemap | Contact