For a school project I want to have a PHP web page with a couple of buttons. When one of the buttons is pressed a c# application needs to perform a certain action depending on which button is pressed. After that the c# application makes a connection to a ESP8266 to perform a electronical action.
To achieve this I want to send a String from the php script when a button is pressed to the c# application. For example "Button1".Then the c# application has something like
if(response == "Button1"){
//perform action
}
To read the PHP I have tried to use the webclient .downloadString(); method.
c#
string urlAddress = "http://localhost/test.php";
using (WebClient client = new WebClient())
{
string pagesource = client.DownloadString(urlAddress);
System.diagnostics.debug.writeline(pagesource)
}
PHP
<form action="/action_page.php" method="get">
<input type="submit" name="submit" value="Submit">
</form>
$var1 = "";
if($_POST['submit']{
$var1 = "button1";
echo var1;
}
I am looping the c# code in a while loop.
When I run this code i see the echo on the webpage screen. But on teh c# site I dont get the value of var1. Instead I get the entire source code of test.php.
So my question is: How do I only pass the value of var1 to my c# application.
Thanks
Sieuwe
NOTE: The PHP may not be 100% correct. I wrote it in stack overflow itself because I had no IDE on the PC where I wrote this question. But the PHP code I used for testing was working!