1
我试图通过URL将python文件中的JSON发送到PHP文件。 PHP文件被调用并正确运行。但它不会捕获我试图发送的msg数据。但它显示NULL。通过URL发送msg从Python到PHP文件的NULL值
myPython.py
import requests, json
url = 'http:/mywebsite.com/api/v1/myPhpFile.php?msg='
payload = {'firstname':'Olivia', 'city':'London', 'country':'UK'}
r = requests.post(url, data=payload)
也试过:
r = requests.post(url, data=json.dumps(payload))
myPHP.php
<?php
...
class AddUser extends Abstractor {
public $log;
public function __construct() {
$this -> log = new MyLogPHP('../includes/debug.log.txt');
}
public function processJob($workerMsg) {
$this -> log -> info($workerMsg, 'W/ADD-USER');
}
}
$addUser = new AddUser();
$response = $addUser -> processJob($_REQUEST['msg']);
在日志中,我得到NULL值。
我甚至通过去掉 '?味精='
myPython.py
import requests, json
url = 'http:/mywebsite.com/api/v1/myPhpFile.php'
payload = {'msg':{'firstname':'Olivia', 'city':'London', 'country':'UK'}}
r = requests.post(url, data=payload)
或
r = requests.post(url, data=json.dumps(payload))
我在做什么错在这里编辑URL尝试?
你发送的请求主体的数据,并试图把它捡起来,在参数网址。这是两回事。研究如何访问PHP中的请求体,或者如何将参数编码到python中的URL中。 –