PythonでJSONをPOSTする
import requests
json_data = {'data':'いちご'}
requests.post(url='***********************', json=json_data)
JSON値をPHPで受け取るサーバ側のコード
<?php
$post_data = json_decode(file_get_contents('php://input'), true); //JSONを受け取る
$data = $post_data["data"];
define("TESTFILE","./all_data.txt");//受け取った値をtxtファイルに書き込む
$fh = fopen(TESTFILE, "w");
fwrite($fh,$data);
fclose($fh);
?>
Pythonでtxtファイルの値を受け取る
data = requests.get('***********************/all_data.txt')
print(data.text)
Why not register and get more from Qiita?
- We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
- you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
Sign upLogin