Search code examples
pythonpython-3.xapirequestmiddleware

How to send a JSON file on an URL in python?


I have a JSON:

url = 'https://your_php_server_url.com/php_endpoint'
payload = {
  'full_name': the_name,
  'phone_number': the_phone,
}

How can I send the json using POST in python?


Solution

  • Python side, you can use requests library:

    import requests
    
    url = 'https://your_php_server_url.com/php_endpoint'
    payload = {
      'full_name': the_name,
      'phone_number': the_phone,
    }
    r = requests.post(url, json=payload)
    print(r.text)