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

工程结构

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

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请求git

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);

服务器响应

客户端响应
flask

发送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);

服务器响应

客户端响应
app

相关文章
相关标签/搜索