[英]file_get_content('php://input') return wrong data
我想將完整的 json 數據發送到我的頁面,我使用 file_get_contents('php://input') 並使用 json_decode() 將其轉換為 json。 但對於 discord 嵌入,file_get_contents() 返回錯誤數據。
Json 字符串: {"embeds":[{"title":"Hello,":"description":"Hi!"}]}
file_get_contents() 返回: embeds=title&embeds=description
我使用 python 請求模塊發送 json:
import requests
data = {"embeds":[{"title":"Hello!","description":"Hi! :grinning:"}]}
headers = {'Content-Type': 'application/json'}
r = requests.post('https://example.com', data=data, headers=headers)
print(r.text)
替代 file_get_contents() 或其他什么?
問題來自 Python 腳本中的請求。 data
參數應作為 JSON 模式的字符串發送。 將import json
添加到您的代碼中,並使用data=json.dumps(data)
而不是data=data
。
有關json.dumps
的更多信息在這里: https://docs.python.org/3/library/json.ZFC356FDC70D28CA76D
r = requests.post('https://example.com', data=json.dumps(data), headers=headers)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.