POST JSON in Python and receive it in PHP

POST JSON in Python

import requests
json_data = {'data':'Strawberry'}
requests.post(url='***********************', json=json_data)

Server-side code that receives JSON values in PHP

<?php
  $post_data = json_decode(file_get_contents('php://input'), true); //Receive JSON
  $data = $post_data["data"];
  define("TESTFILE","./all_data.txt");//Write the received value to a txt file
  $fh = fopen(TESTFILE, "w");
  fwrite($fh,$data);
  fclose($fh);
 ?>

Receive the value of a txt file in Python

data = requests.get('***********************/all_data.txt')
print(data.text)

Recommended Posts

POST JSON in Python and receive it in PHP
POST the image with json and receive it with flask
Check and receive Serial port in Python (Port check)
POST variously with Python and receive with Flask
Read and write JSON files in Python
Handling json in python
Receive and display HTML form data in Python
Reading and writing CSV and JSON files in Python
Receive the form in Python and do various things
Mutual conversion between JSON and YAML / TOML in Python
Read json file with Python, format it, and output json
How to handle JSON in Ruby, Python, JavaScript, PHP
Easily format JSON in Python
POST json with Python3 script
Receive runtime arguments in Python 2.7
Stack and Queue in Python
Unittest and CI in Python
Post to Slack in Python
Try to make it using GUI and PyQt in Python
Object-oriented in C: Refactored "○ ✕ game" and ported it to Python
Install CaboCha in Ubuntu environment and call it with Python.
Just try to receive a webhook in ngrok and python
MIDI packages in Python midi and pretty_midi
Difference between list () and [] in Python
Difference between == and is in python
View photos in Python and html
Write JSON Schema in Python DSL
Sorting algorithm and implementation in Python
Manipulate files and folders in Python
About dtypes in Python and Cython
Dynamically load json type in python
Handling of JSON files in Python
Assignments and changes in Python objects
JSON encoding and decoding with python
Ciphertext in Python: IND-CCA2 and RSA-OAEP
Hashing data in R and Python
Get, post communication memo in Python
Function synthesis and application in Python
Export and output files in Python
Python logging and dump to json
Reverse Hiragana and Katakana in Python2.7
Reading and writing text in Python
[GUI in Python] PyQt5-Menu and Toolbar-
Create and read messagepacks in Python
processing to use notMNIST data in Python (and tried to classify it)
How to install OpenCV on Cloud9 and run it in Python
Read big endian binary in Python and convert it to ndarray
Overlapping regular expressions in Python and Java
Differences in authenticity between Python and JavaScript
Notes using cChardet and python3-chardet in Python 3.3.1.
Differences between Ruby and Python in scope
AM modulation and demodulation in Python Part 2
difference between statements (statements) and expressions (expressions) in Python
Eigenvalues and eigenvectors: Linear algebra in Python <7>
[Python] Sweet Is it sweet? About suites and expressions in the official documentation
Line graphs and scale lines in python
Obtaining temporary AWS credentials in PHP, Python
Implement FIR filters in Python and C
Differences in syntax between Python and Java
Difference between PHP and Python finally and exit
Search and play YouTube videos in Python