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

相關文章
相關標籤/搜索