共計 593 個字符,預計需要花費 2 分鐘才能閱讀完成。
要調(diào)用 PHP 接口,可以使用 Python 的 requests 庫發(fā)送 HTTP 請求。以下是一個簡單的示例:
import requests
url = 'http://example.com/api'
headers = {'Content-Type': 'application/json'}
data = {'key1': 'value1', 'key2': 'value2'}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print(response.json())
else:
print('Error:', response.text)
在這個示例中,我們使用 requests 庫發(fā)送一個 POST 請求到 http://example.com/api,并傳遞了一些數(shù)據(jù)。接口返回的數(shù)據(jù)可以通過 response.json() 方法獲取。如果請求失敗,可以通過 response.text 獲取錯誤信息。
請注意,具體的請求參數(shù)和請求方法可能會根據(jù)接口的要求而有所不同。您可能需要根據(jù)接口文檔調(diào)整代碼中的 URL、請求頭和數(shù)據(jù)參數(shù)。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完