python - 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:
怎么了?
解决方案
只需替换$_GET
为$_POST
.
推荐阅读
- sql-server - 如何根据日期进行滚动周?
- android - 除非进度值和最大值相同,否则 Android ProgressBar 不起作用
- python - Kivy - 如何调用对象方法但不运行其 __init__
- azure-devops - Azure Devops 发布管道 - 匹配分支门
- javascript - 移动视图中缺少高图表项
- ruby-on-rails - 寻找可能导致麻烦的 Ruby 猴子补丁的来源?
- angular - Angular 9 - 不能在 ngFor 语句中使用 Observable
- if-statement - lisp中有嵌套的if吗?
- c++ - 如何在没有大量重复检查代码的情况下处理函数的多个可能的早期返回
- python - 带有 r 对数刻度的径向图的刻度位置