c++向flask 发送get和post请求

工程结构

《c++向flask 发送get和post请求》

项目地址https://git.ustclug.org/peter_lee/cppSendPostAndGetToFlask

flask 服务器端

from flask import Flask , render_template,request
app = Flask(__name__)

@app.route('/')
def hello_world():
    return render_template('index.html')

@app.route('/postdata', methods=['POST'])
def postdata():
    print  request.form.get('key1')
    return  "ok"

if __name__ == '__main__':
    app.run()

C++客户端

发送get请求

QString url_str = "http://127.0.0.1:5000";
HttpRequestWorker worker;
QObject::connect(&worker, SIGNAL(on_execution_finished(HttpRequestWorker*)), &w, SLOT(handle_result(HttpRequestWorker*)));
worker.execute(&input);

服务器响应
《c++向flask 发送get和post请求》
客户端响应
《c++向flask 发送get和post请求》

发送post请求

QString url_str = "http://127.0.0.1:5000/postdata";
HttpRequestInput input(url_str, "POST");
input.add_var("key1", "<a><b></b></a>");
HttpRequestWorker worker;
QObject::connect(&worker, SIGNAL(on_execution_finished(HttpRequestWorker*)), &w, SLOT(handle_result(HttpRequestWorker*)));
worker.execute(&input);

服务器响应
《c++向flask 发送get和post请求》
客户端响应
《c++向flask 发送get和post请求》

    原文作者:wzyuliyang
    原文地址: https://segmentfault.com/a/1190000002910103
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞