首页 > 解决方案 > Python 向 PHP 发送信息

问题描述

我有这个代码:

data.py

import requests
userdata = {"firstname": "John", "lastname": "Doe", "password": "jdoe123"}
resp = requests.post('http://127.0.0.1/post.php', params=userdata)
print(resp.content)

post.php

<?php 
$firstname = htmlspecialchars($_GET["firstname"]);
$lastname = htmlspecialchars($_GET["lastname"]);
$password = htmlspecialchars($_GET["password"]);
echo "firstname: $firstname lastname: $lastname password: $password";
?>

在我的本地主机中,页面如下所示:

Notice: Undefined index: firstname in C:\xampp\htdocs\post.php on line 2

Notice: Undefined index: lastname in C:\xampp\htdocs\post.php on line 3

Notice: Undefined index: password in C:\xampp\htdocs\post.php on line 4

firstname: lastname: password:

怎么了?

标签: pythonphppython-requestsscripting

解决方案


只需替换$_GET$_POST.


推荐阅读