Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

PythonでJSONをPOSTし、PHPで受け取る

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?
  1. 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
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away