1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-11-04

#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)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?