python做http請求
基於flask,封裝http服務
#客戶端
import requests
url = 'http://127.0.0.1:16701/mail/sendmail'
response = requests.post(url,data={"subject":"subject","body":"Test","to":["test@163.com","wej@qq.com"]})
print(response)
print(response.text)
#伺服器端
# coding: utf-8
#encoding: utf-8
import json
import requests
from flask import Flask
from flask_restful import Api
from flask_restful import Resource
from flask_restful .reqparse import RequestParser
import datetime
app = Flask(__name__)
api = Api(app)
class sends:
class QueryApi(Resource):
def __init__(self):
# 使用者請求引數校驗
self.reqparse = RequestParser()
self.reqparse.add_argument('subject', required=False, type=str,default='error')
self.reqparse.add_argument('body', required=True, type=str)
self.reqparse.add_argument('format', required=False, type=str,default='plain')
self.reqparse.add_argument('from', required=False, type=str,default='youxiang@qq.com')
self.reqparse.add_argument('to', required=True, type=str,action='append')
super(QueryApi, self).__init__()
def post(self):
# print('here')
params = self.reqparse.parse_args()
nowtime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#現在時間
print(nowtime)
print(params)
print(params)
# print(q2)
return {'result':params}
BASE_URL = '/mail'
api.add_resource(QueryApi, '%s/sendmail' % BASE_URL, endpoint='sendmail')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=16701)
相關文章
- python-http請求帶AuthorizationPythonHTTP
- python傳送HTTP POST請求PythonHTTP
- Python中get、post請求詳解(HTTP請求頭、狀態碼)PythonHTTP
- http請求概述HTTP
- Jsoup http請求JSHTTP
- go http請求GoHTTP
- 使用Python獲取HTTP請求頭資料PythonHTTP
- 合併HTTP請求vs並行HTTP請求,到底誰更快?HTTP並行
- 合併HTTP請求 vs 並行HTTP請求,到底誰更快?HTTP並行
- HTTP請求報文HTTP
- Cookie 與 HTTP請求CookieHTTP
- 前端巧用localStorage做“快取”,減少HTTP請求次數前端快取HTTP
- python收到MQTT訊息後再發http請求PythonMQQTHTTP
- python全棧02-----url_for,HTTP的請求方法Python全棧HTTP
- Http請求資料格式HTTP
- HTTP 請求與響應HTTP
- Http請求與響應HTTP
- Http請求相關(轉)HTTP
- go搞笑http請求庫GoHTTP
- HTTP網路請求原理HTTP
- go http請求流程分析GoHTTP
- HTTP請求預設值HTTP
- HTTP的請求過程HTTP
- java傳送http請求JavaHTTP
- HTTP GET請求傳bodyHTTP
- golang 的 http 請求池GolangHTTP
- 七種HTTP請求方法HTTP
- Http請求體詳解HTTP
- Java實現Http請求JavaHTTP
- HTTP請求格式和HTTP響應格式HTTP
- Python 之requests封裝通用http協議介面請求Python封裝HTTP協議
- 【HTTP】HTTP請求體中的四種格式HTTP
- face 31減少http請求HTTP
- HTTP的請求與響應HTTP
- Go如何響應http請求?GoHTTP
- 使用 Netcat 模擬 HTTP 請求HTTP
- golang常用的http請求操作GolangHTTP
- 教你玩轉HTTP—請求方法HTTP