1

i want to get full json data sent to my page, im using file_get_contents('php://input') and i convert it into json using json_decode(). But for discord embeds, file_get_contents() return wrong data.

Json string : {"embeds":[{"title":"Hello!","description":"Hi!"}]}

file_get_contents() return : embeds=title&embeds=description

i use python requests module to send 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)

alternative to file_get_contents() or something else ?

6
  • I think the problem is made by the front-end. Can you attach the code that you are using for sending data? Commented Jan 23, 2022 at 18:30
  • First you extract embeds then in embeds, you extract the json data at index 0 of embeds which is now your fully formed json data. Commented Jan 23, 2022 at 18:32
  • @AmirrezaNoori i use print_r() function to get file_get_contents() return $data = file_get_contents('php://input'); print_r($data); Commented Jan 23, 2022 at 18:39
  • I mean, how do you send this JSON to the PHP page? Commented Jan 23, 2022 at 18:41
  • oh i use python requests module @AmirrezaNoori Commented Jan 23, 2022 at 18:42

1 Answer 1

0

The problem is from the request in the Python script. data parameter should send as a string for JSON mode. add import json to your code and use data=json.dumps(data) instead of data=data.

More information about json.dumps is here: https://docs.python.org/3/library/json.html

r = requests.post('https://example.com', data=json.dumps(data), headers=headers)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.