- Create a new Console Application
- Declare four variables req, response, output and reader as WebRequest, WebResponse, Stream and StreamReader
- Create an web request using WebRequset.Create(string url)
(e.g. req = WebRequest.Create(http://localhost/index.php);) - Set WebRequest method as POST
(req.Method = "POST"); - Set :
response = req.GetResponse();
output = response.GetResponseStream();
reader = new StreamReader(output); - Now reader has the output from the PHP file
- To read from the reader, reader.ReadLine() method can be used
Example:
(C# : phpEchoReader.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;namespace phpEchoReader {
class Program {
static void Main(string[] args) {
WebRequest req;
WebResponse response;
Stream output;
StreamReader reader;
req =
WebRequest.Create("http://localhost/index.php");
req.Method = "POST";
response = req.GetResponse();
output = response.GetResponseStream();
reader = new StreamReader(output);
while (!reader.EndOfStream)
{
Console.WriteLine(reader.ReadLine());
}
Console.WriteLine("Press any key too continue...");
Console.ReadLine();
}
}
}
(php code: index.php)
for ($i = 0; $i <>
echo $i."\n";
?>
Output:
No comments:
Post a Comment