收到POST请求后更新网页 [英] Update webpage after receiving POST request

查看:110
本文介绍了收到POST请求后更新网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试找出堆栈溢出中的类似问题,但是我做不到.我正在使用python请求库将POST请求发送到我的个人域名www.****.com.

I've to tried to find out similar issue in stack overflow, but I couldn't. I am using python requests library to send POST request to my personal domain name www.****.com.

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

当我运行脚本时,r.text显示"Welcome Anum".我在网站上写了一个小的php脚本的地方

When I run the script, the r.text shows me "Welcome Anum". Where I have written a small php script on my website

<?php
      $data=$_POST["temp1"];
      echo "Welcome ". $data. "<br />";
?>     

现在的问题是,即使刷新页面后,我也无法在实际网站上看到此获取请求.我尝试每3秒循环发送一次POST请求,但在实际网站上仍然看不到任何更新.我是否需要循环我的php代码以持续侦听来自客户端的请求? 我的理解是,我的域名用作服务器,而python脚本用作客户端,因此当客户端向服务器发送请求时,如何管理服务器以捕获该请求并显示在网页上?

Now the problem is, I am not able to see this get request on actual website, even after refreshing the page. I tried sending POST request in a loop after every 3 seconds, but still can't see any update on actual website. Do I need to loop up my php code to continuously listen for requests from client ? My understanding is that my domain name is working as Server and python script as client, so as the client send request to server, how do I manage my server to catch that request and display on web page ?

推荐答案

我了解您希望python脚本发送一个变量,该变量对网站的其他访问者可见吗? 您需要将从python接收到的值存储在某个地方,例如存储在数据库中.然后,您可以读取该值并将其显示给访问者.

I understand you want the python script to send a variable, which will be visible to other visitors of the website? You need to store the value which you recieve from python somewhere, like in a database. Then you can read that value and show it to the visitor.

这篇关于收到POST请求后更新网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆