0
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?

Flask requestsを使った受け渡し

Last updated at Posted at 2024-06-03

サーバ側

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/EmployeeSystem', methods=['POST'])
def register():
    data = request.get_json()
    id = data.get('id')
    name = data.get('name')
    

    data = {
        f"id: {id}, name: {name}"
    }
    
    return jsonify(data), 200

if __name__ == '__main__':
    app.run(host="0.0.0.0")

リクエスト側

import requests

url = 'http://127.0.0.1:5000/EmployeeSystem'

data = {
    'id': 1,
    'name': '小林'
}

response = requests.post(url, json=data)

print("Response from server:", response.json())
print("Status code:", response.status_code)

レスポンスコードの表示

0
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
0
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?