简体   繁体   English

在服务器上看不到我的POST请求

[英]Can't see my POST request on server

I am trying with a very simple example where my data is temperature, and I want it to be seen on my website index.php page after I successfully POST data from my python code. 我正在尝试一个非常简单的示例,其中我的数据是温度,在我成功从python代码发布数据后,希望在我的网站index.php页面上看到它。

Heres my simple index.php code; 这是我简单的index.php代码;

    <?php

       echo 'Hello ' . $_POST["temp1"] . '!';
       $data=$_POST["temp1"];
    ?>

  <html>
    <head>
       <title>Sensor Data</title>
    </head>
  <body>
   <h1>HELLO </h1>

  <?php 
     printf("<tr><td> &nbsp;%s </td></tr>", $data)
  ?>

 </table>
</body>
</html>  

I am sending a POST request using requests from python, 我正在使用来自python的请求发送POST请求,

import requests
r = requests.post("http://www.********.com", data={"temp1":"Anum"})
print(r.text)

My POST request works perfect, and I can see the result of print(r.text) as "Hello: Anum! " , But it actually doesn't appears on my server index.php page even if I refresh it. 我的POST请求工作完美,并且可以将print(r.text)的结果显示为“ Hello:Anum!”,但是即使刷新它,它实际上也不会出现在服务器的index.php页面上。 What can be the reason ? 可能是什么原因? Thanks i advance for everyones help :) 谢谢我提前给大家的帮助:)

   $data=$_POST["name"];

不熟悉Python与PHP的接口,但是不应该那样吗?(下)

   $data=$_POST["temp1"];

You are not storing storing the data on the server. 您没有将数据存储在服务器上。 Every time you refresh the page (which includes when you POST to it in python) the script will run from the start. 每次刷新页面时(包括在python中POST到该页面时),脚本都会从头开始运行。 It works when you POST to it in python because it has the value that you send to it when it renders (ie, executes the php code), but when the browser requests it and doesn't send the POST data then the variables will be left unset. 当您在python中对其进行POST时,它可以工作,因为它具有您在渲染时发送给它的值(即执行php代码),但是当浏览器请求它并且不发送POST数据时,变量将是保持不变。

You may want to look into a relational database such as MySQL which is very easy to implement with php. 您可能想研究一个关系数据库,例如MySQL,它很容易用php实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM