Qt---QTcpSocket连接http服务器
来源:互联网 发布:什么软件字体多 编辑:程序博客网 时间:2024/05/29 15:03
tcp.pro
#-------------------------------------------------## Project created by QtCreator 2016-06-29T20:24:24##-------------------------------------------------QT += core networkQT -= core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = tcpCONFIG += consoleCONFIG -= app_bundleTEMPLATE = appSOURCES += main.cpp\ client.cppHEADERS += \ client.h
client.h
#ifndef CLIENT_H#define CLIENT_H#include <QTcpSocket>class Client: public QObject{ Q_OBJECT public: Client(): m_socket(0){} ~Client(){} void startConnect(QString host, quint16 prot); //连接主机 protected slots: void onConnected(); //发送 void onReadyRead(); //读取 private: QTcpSocket *m_socket;};#endif
client.cpp
#include "client.h"#include <QDebug>void Client::startConnect(QString host, quint16 port){ m_socket = new QTcpSocket(this); connect(m_socket, SIGNAL(connected()), this, SLOT(onConnected())); connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); m_socket->connectToHost(host, port); //连接主机}void Client::onConnected(){ m_socket->write("GET / HTTP/1.1\r\n\r\n"); //向服务器端发送数据,http头部}void Client::onReadyRead() //接收数据{ qDebug() << m_socket->readAll(); //打印出来}
main.cpp
#include "mainwindow.h"#include "client.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); Client client; client.startConnect("www.baidu.com", 80); return a.exec();}
0 0
- Qt---QTcpSocket连接http服务器
- Qt QTcpSocket 对连接服务器中断的不同情况进行判定
- Qt QTcpSocket 对连接服务器中断的不同情况进行判定
- qt http连接
- QT QTcpSocket发送数据问题
- android http连接服务器
- QTcpSocket类 客户端/服务器模式
- QTcpSocket服务器 定时器,多线程结合
- QTcpSocket
- QTcpsocket
- Qt QTcpSocket 设置本地源端口
- Qt之QTcpServer/QTcpSocket简单收发信息
- Qt: 基于QTcpSocket的聊天程序
- Qt之QTcpServer/QTcpSocket简单收发信息
- 短连接http服务器陷阱
- android HTTP形式连接服务器
- Android开发 Http连接服务器
- 服务器HTTP长连接与短连接
- linux内核栈与用户栈及调用栈观察方法
- Hanoi in Prolog
- C++标准库类型——string
- JAVA并发集合学习总结
- SpringMVC请求后台地址URL没有.*的几种实现方式
- Qt---QTcpSocket连接http服务器
- 图的遍历
- 加速android studio速度
- 重构系列:概论
- Android NDK编译环境配置
- Maven安装和简单入门(1)
- Centos配置yum源
- 258. Add Digits
- 简单三层加存储过程实现新闻列表分页