[英]Python sending information to 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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.