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 OPTIONS請求PythonHTTP
- Jmeter做效能測試——HTTP請求JMeterHTTP
- python-http請求帶AuthorizationPythonHTTP
- python傳送HTTP POST請求PythonHTTP
- http請求HTTP
- HTTP 請求HTTP
- http請求概述HTTP
- HTTP請求方法HTTP
- http請求頭HTTP
- go http請求GoHTTP
- Python中get、post請求詳解(HTTP請求頭、狀態碼)PythonHTTP
- Python中http請求方法庫彙總PythonHTTP
- 合併HTTP請求vs並行HTTP請求,到底誰更快?HTTP並行
- 合併HTTP請求 vs 並行HTTP請求,到底誰更快?HTTP並行
- Cookie 與 HTTP請求CookieHTTP
- Jsoup http請求JSHTTP
- Android Http請求AndroidHTTP
- HTTP請求報文HTTP
- 前端巧用localStorage做“快取”,減少HTTP請求次數前端快取HTTP
- Swift: 用Alamofire做http請求,用ObjectMapper解析JSONSwiftHTTPObjectAPPJSON
- 使用Python獲取HTTP請求頭資料PythonHTTP
- 【轉】怎麼用PHP傳送HTTP請求(POST請求、GET請求)?PHPHTTP
- HTTP的請求過程HTTP
- Http請求資料格式HTTP
- HTTP GET請求傳bodyHTTP
- golang 的 http 請求池GolangHTTP
- HTTP 請求與響應HTTP
- Java實現Http請求JavaHTTP
- go http請求流程分析GoHTTP
- 七種HTTP請求方法HTTP
- Http請求體詳解HTTP
- HTTP網路請求原理HTTP
- HTTP請求預設值HTTP
- Http請求相關(轉)HTTP
- 我知道的HTTP請求HTTP
- Http請求與響應HTTP
- AJAX 跨源 HTTP 請求HTTP
- .NET處理HTTP請求HTTP