Php 未从http post接收数据
我使用python代码发送http post请求,在另一端(服务器)使用php脚本获取数据并向客户端发送确认。 当我尝试将数据发送到服务器时,它没有收到数据。我的回答是“什么都没有”,当它无法读取数据时,我试图打印它 这是我的python代码Php 未从http post接收数据,php,python,http-post,Php,Python,Http Post,我使用python代码发送http post请求,在另一端(服务器)使用php脚本获取数据并向客户端发送确认。 当我尝试将数据发送到服务器时,它没有收到数据。我的回答是“什么都没有”,当它无法读取数据时,我试图打印它 这是我的python代码 # importing the requests library import requests # defining the api-endpoint API_ENDPOINT = "http://192.168.X.XX/response.php"
# importing the requests library
import requests
# defining the api-endpoint
API_ENDPOINT = "http://192.168.X.XX/response.php"
# your source code here
Driver-id = 'TN597098'
Driver-name = 'XXXX'
# data to be sent to api
data = {'driverid':Driver-id,'drivername':Driver-name}
# sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
# extracting response text
response = r.text
print("The response is:%s"%response)
这是我的php脚本
<?php
if(isset($_GET['driverid'])) {
echo $_GET['driverid'];
} else {
echo "nothing";
}
?>
如果使用http post方法发送请求,那么在PHP中必须使用$\u post
<?php
if(isset($_POST['driverid'])) {
echo $_POST['driverid'];
} else {
echo "nothing";
}
您正在从python脚本执行POST调用,并希望在php脚本中获得GET,这就是它无法工作的原因。
您可以将php代码更改为
<?php
if(isset($_POST['driverid'])) {
echo $_POST['driverid'];
} else {
echo "nothing";
}
?>