【python】python使用requests 发送请求

POST

import requests
import json

def post_request():
        headers = {'content-type': "application/json"}
        url = "http://127.0.0.1:9200/test/_delete_by_query" 
        data = {
                "query": {
                        "match_all": {}
                }
        }
        x = requests.post(url, data = json.dumps(data), headers = headers, timeout=60)
        print(x.text)

GET

import requests
import json

def get_request():
     url = "http://10.11.68.224:8888/api/admin/queries/rq_status"
     headers = {"Content-Type":"application/x-www-form-urlencoded", "Authorization": "uyyP3NuSYmQKkLjCRJmm3lPYktLErITD7rt6cVSb"}
     result = requests.get(url,  headers = headers)
     print(result.text)
 
 
if __name__ == '__main__':
     get_request()
posted @ 2022-11-10 19:24  彬在俊  阅读(118)  评论(0编辑  收藏  举报