Browser not displaying POST data PHP?
Question: I have written a program to send data from python to PHP. The python code is
as follows:

    
    
    import urllib2, urllib
    mydata=[('one','Check'),('two','Mate')]    #The first is the var name the second is the value
    mydata=urllib.urlencode(mydata)
    path='http://localhost/index.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
    

The corresponding index.php PHP script is as follows:

    
    
    <?php
    echo $_POST['one'];
    echo $_POST['two'];
    ?>
    

However, when I run index.php from localhost, it is not displaying anything. I
think it should be displaying CheckMate. But when running the python script I
get the response back. print page prints CheckMate

Where could be the problem?


Answer: By default Python is sending as `GET` request.

You need to specify it as a `POST` request.

    
    
    req=urllib2.Request('POST', path, mydata)
    

