How to Read PHP Requests & Responses in ASP.NET
You can develop a Web application in PHP but use the Microsoft .NET framework to process the input from the PHP front-end software. The .NET framework has a "WebRequest" class library that opens a PHP page and retrieves the values sent by the PHP page. You use this process to read values from a PHP page using custom software developed in the Microsoft .NET Visual Studio software.
Instructions
-
-
1
Open the Visual Studio software and open the .NET project you want to use to retrieve values from the PHP pages.
-
2
Create the request to open the Web page. The following code opens the PHP page "index.php" on the site named "mysite.com":
WebRequest request = WebRequest.Create("http://mysite.com/index.php);
-
-
3
Get the response from the PHP page. The response variable contains the data returned by the PHP page. The following sets up the response variable:
WebResponse response = request.GetResponse();
-
4
Convert the response data to a string so you can display the results to the reader. The following code converts the PHP response to a string and stores the data in a variable named "phpstring":
Stream data= response.GetResponseStream ();
StreamReader sr = new StreamReader (data);
string phpstring= sr.ReadToEnd (); -
5
Display the results to the .NET console. The following code shows you how to display the PHP response in the .NET software:
Console.WriteLine (phpstring);
-
1