【发布时间】:2022-01-23 18:24:27
【问题描述】:
我想将完整的 json 数据发送到我的页面,我使用 file_get_contents('php://input') 并使用 json_decode() 将其转换为 json。但是对于不和谐的嵌入,file_get_contents() 返回错误的数据。
Json 字符串:{"embeds":[{"title":"Hello!","description":"Hi!"}]}
file_get_contents() 返回:embeds=title&embeds=description
我使用 python requests 模块发送 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() 或其他?
【问题讨论】:
-
我认为问题出在前端。你能附上你用来发送数据的代码吗?
-
首先提取嵌入,然后在嵌入中提取嵌入索引 0 处的 json 数据,该数据现在是完全形成的 json 数据。
-
@AmirrezaNoori 我使用 print_r() 函数来获取 file_get_contents() return $data = file_get_contents('php://input'); print_r($data);
-
我的意思是,你如何将这个 JSON 发送到 PHP 页面?
-
哦,我使用python请求模块@AmirrezaNoori
标签: php json file-get-contents