我正在嘗試將發布請求(包含特定引數和值)發送到 php 服務器(指示檢查指定請求是否具有某些引數,在這種情況下它將值保存到資料庫中)。
使用以下 curl 命令,我可以成功地將請求注冊到服務器資料庫中:
sudo curl -d 'hostname=RegisterTest&ip=127.0.0.1&operatingsystem=testOpsys' -X POST http://localhost/register.php
這也是我試圖用python 腳本模擬的 curl 命令。問題是我嘗試了各種 python 語法,但我無法復制 curl 命令,即使發送了請求(并且收到了服務器回應),注冊也不會發生。
import requests
url = “http://localhost/register.php”
data = {'hostname=RegisterTest&ip=127.0.0.1&operatingsystem=testOpsys'}
response = requests.post(url, data=data)
print(response)
uj5u.com熱心網友回復:
您需要將資料格式化為字典。
import requests
data = {
'hostname': 'RegisterTest',
'ip': '127.0.0.1',
'operatingsystem': 'testOpsys'
}
response = requests.post('http://localhost/register.php', data=data)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/420248.html
標籤:
