Simple http post request demo

 1 // httppostdemo.h
 2 #ifndef HTTPPOSTDEMO_H
 3 #define HTTPPOSTDEMO_H
 4
 5 #include <QMainWindow>
 6 #include <QNetworkAccessManager>
 7 #include <QNetworkReply>
 8
 9 namespace Ui {
10 class HttpPostDemo;
11 }
12
13 class HttpPostDemo : public QMainWindow
14 {
15     Q_OBJECT
16
17 public:
18     explicit HttpPostDemo(QWidget *parent = 0);
19     ~HttpPostDemo();
20
21 private slots:
22     void on_pushButton_clicked();
23     void slotFinished(QNetworkReply *reply);
24
25 private:
26     Ui::HttpPostDemo *ui;
27     QNetworkAccessManager *m_manager;
28 };
29
30 #endif // HTTPPOSTDEMO_H
 1 // httppostdemo.cpp
 2 #include "httppostdemo.h"
 3 #include "ui_httppostdemo.h"
 4
 5 #include <QDebug>
 6 #include <QNetworkRequest>
 7
 8 HttpPostDemo::HttpPostDemo(QWidget *parent) :
 9     QMainWindow(parent),
10     ui(new Ui::HttpPostDemo)
11 {
12     ui->setupUi(this);
13
14     m_manager = new QNetworkAccessManager(this);
15     connect(m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotFinished(QNetworkReply*)));
16 }
17
18 HttpPostDemo::~HttpPostDemo()
19 {
20     delete ui;
21 }
22
23 void HttpPostDemo::slotFinished(QNetworkReply *reply)
24 {
25     qDebug() << reply->readAll();
26 }
27
28 void HttpPostDemo::on_pushButton_clicked()
29 {
30     QNetworkRequest *req = new QNetworkRequest();
31     req->setUrl(QUrl("http://zc.7k7k.com/post_login"));
32     req->setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded; charset=UTF-8");
33     req->setRawHeader("Accept","application/json, text/javascript, */*; q=0.01");
34     req->setRawHeader("Accept-Language","zh-CN,zh;q=0.8");
35     req->setRawHeader("X-Requested-With","XMLHttpRequest");
36     req->setRawHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
37     req->setRawHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
38     // req->setRawHeader("Accept-Encoding","gzip,deflate");
39     req->setRawHeader("Host","zc.7k7k.com");
40     req->setRawHeader("Connection","Keep-Alive");
41     req->setRawHeader("Cache-Control","no-cache");
42     QByteArray data;
43     data.append("username=username&password=password&autologin=checked&rf=http://www.7k7k.com/#bottom");
44     m_manager->post(*req, data);
45 }
 1 // main.cpp
 2 #include "httppostdemo.h"
 3 #include <QApplication>
 4
 5 int main(int argc, char *argv[])
 6 {
 7     QApplication a(argc, argv);
 8     HttpPostDemo w;
 9     w.show();
10
11     return a.exec();
12 }
时间: 2024-10-15 00:19:51

Simple http post request demo的相关文章

scala: How to write a simple HTTP GET request client in Scala (with a timeout)

Scala CookBook: http://scalacookbook.com/ @throws(classOf[java.io.IOException]) @throws(classOf[java.net.SocketTimeoutException]) def get(url: String, connectTimeout:Int =5000, readTimeout:Int =5000, requestMethod: String = "GET") = { import jav

包装 request Demo

1 //包装request,增强getParameter方法 2 class MyReq extends HttpServletRequestWrapper{ 3 private HttpServletRequest req; 4 public MyReq(HttpServletRequest req) {//构造,必须 5 super(req); 6 this.req=req; 7 } 8 9 @Override 10 public String getParameter(String nam

a simple machine learning system demo, for ML study.

Machine Learning System introduction This project is a full stack Django/React/Redux app that uses token based authentication with Knox. Then I add Machine Learning features for demostrate the full workflow of the data mining, including the four stag

Demo on bar code printing using SAP Scripts/Smart forms

This document will explain the printing of bar code using SAP Scripts/Smart forms Target Readers: SAP-ABAP consultants with knowledge of layout designing. Definition:  Bar codes are often printed on labels to allow machine to read the data. SAP has p

lucene-5.1.0 索引的创建与查询 demo

lucene以及solr作为索引工具已经被广泛使用,以前项目中也有用到过lucene4.x,如今lucene版本已经到5.1了,再次了解一下,来写个demo! 首先附一下文档及下载地址: a:下载地址 Lucene下载 b:文档地址 lucene API 所需jar包(只附lucene相关jar): lucene-analyzers-common-5.1.0.jar lucene-core-5.1.0.jar lucene-queries-5.1.0.jar lucene-queryparser

网上搜集第三方(二)

這是我收集了一些第三方的 Library,大部份都還沒用過Orz,只是這樣整理以後要用到的時候會比較好找到. UI UI Design alertView Menu(選單) Side ViewController UICollectionView Segment Control Others 動畫 影像特效 模糊.毛玻璃效果(Blur) 畫面轉換 各種統計圖表 Line Bar Pie Others Pull To ReFresh Notification Auto Layout Data St

Spring3.0实现REST实例

Spring3.0实现REST实例 这是一个rest风格的访问,Spring从3.0开始将全面支持rest.不得不感叹Spring的强悍. 项目结构: 第一步永远是配置,使用框架永远都是先有配置,在web.xml中的配置: [xhtml] view plaincopy <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://

Oracle UTL_HTTP(收集汇总有用资料)

From Oracle The UTL_HTTP package makes Hypertext Transfer Protocol (HTTP) callouts from SQL and PL/SQL. You can use it to access data on the Internet over HTTP. When the package fetches data from a Web site using HTTPS, it requires Oracle Wallet Mana

[Java] JSP笔记 - 自定义标签

自定义标签的创建步骤: 自定义标签的四大功能: 自定义标签的类结构: 在 1.0 中呢, 可以将 <body-content> 的值设置为 JSP, 2.0中则不允许在自定义标签体中出现jsp代码. 接下来呢,我直接贴一些Demo代码: tagdatetag.tld  (标签声明 XML,将之方于 WEB-INF 目录中) <?xml version="1.0" encoding="UTF-8"?> <taglib xmlns=&quo