dongqian1893 2018-11-21 20:38
浏览 32

如何将String从php传递给C#

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line