I am trying to send data from my python file to a php file and show it inside the browser.
I've read the following question: Sending data using POST in Python to PHP and I am basing my code on the answer of the question.
My python code thus far is :
import urllib2, urllib
def main():
mydata = [('one', '1'), ('two', '2')] # The first is the var name the second is the value
mydata = urllib.urlencode(mydata)
path = 'http://localhost/test2.php' # the url you want to POST to
req = urllib2.Request(path, mydata)
req.add_header("Content-type", "application/x-www-form-urlencoded")
page = urllib2.urlopen(req).read()
print page
if __name__ == "__main__":
main()
My php code is:
<meta http-equiv="refresh" content="1" /> <!-- Updates the whole page each second -->
<?php
echo $_POST['one'];
echo "\n";
echo $_POST['two'];
?>
I am updating the page but it never shows 1 and 2 in the browser, it does show the 1 and 2 printed in python. Is there a way how I can update the php file so it shows everything I send to it?
Thank you!