簡體   English   中英

file_get_content('php://input') 返回錯誤數據

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM