1、在.pro文件里添加
QT += network
2、QT端代码示例
#include "mainwindow.h"
#include <QApplication>
#include <QNetworkReply>
#include <QNetworkRequest>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
// URL
QString baseUrl = "https://http:127.0.0.1/postdata";
QUrl url(baseUrl);
// 表单数据
QByteArray dataArray;
dataArray.append("MSH=12");
// 构造请求
QNetworkRequest request;
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
request.setUrl(url);
QNetworkAccessManager *manager = new QNetworkAccessManager();
// 发送请求
manager->post(request, dataArray);
return a.exec();
}
3、Flask代码示例
from flask import Flask
from flask import request
import json
app = Flask(__name__)
@app.route("/")
def index():
return "Hello"
resSets = {}
@app.route('/postdata', methods=['POST'])
def postdata():
data = request.form.get("MSH")
print(data)
return json.dumps(resSets, ensure_ascii=False)
if __name__=="__main__":
app.run(host="0.0.0.0", port=8090)
输出: