Apache server is installed in one machine and there is a .php script present in the server. Now from my win32 or c# application how do I invoke the script and how to receive the data from the server?
2 Answers
Its the same as reading output from any web page, the php script is processed by the server
This code reads the output of a php page from the php.net online manual:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(@"http://www.php.net/manual/en/index.php");
using (HttpWebResponse resp = (HttpWebResponse) wr.GetResponse())
{
StreamReader sr = new StreamReader(resp.GetResponseStream());
string val = sr.ReadToEnd();
Debug.WriteLine(val);
}
4 Comments
Naruto
Hey, Thanks Matt.. But We do have script located in server, how do i invoke.. if i do like your method i can get the content, but i want to know how to execute a script in server.. how to do?
Matt
As I understand it, the web server is configured to execute the script when clients request it, and the script can output content back to the client browser. PHP needs to be set up on the web server and the web server configured to recognise requests for .php files to be executed as scripts.
Zakos
what about input/argument ?
Matt
@Zakos again, its the same. If the page accepts query string parameters you can add them to the URL, if it accepts post data you can issue a post request and provide a request body.