Naruto
Naruto

Reputation: 9634

How do I invoke a PHP script on a Web server?

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?

Upvotes: 0

Views: 2124

Answers (2)

Matt
Matt

Reputation: 3014

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);
}

Upvotes: 2

CodeJoust
CodeJoust

Reputation: 3800

You need to open a network connection to localhost, or use the php command-line interpreter, but I'm not sure if that is linux-only, it should work for windows... try php (filename.php) to execute and return the echoed output.

Upvotes: 0

Related Questions