当前位置: 首页 > news >正文

MFC发送http https以及json解析

域名解析成IP

		char szWeb[128] = "www.baidu.com";struct hostent *pHost = NULL;pHost = gethostbyname(szWeb);//完成主机名到域名的解析char *IP = inet_ntoa(*((struct in_addr *)pHost->h_addr));CString ipStr = IP;

请求三部曲:

1、CInternetSession session;

		CInternetSession session;session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000 * 20);

2、CHttpConnection* pConnection;

		CHttpConnection* pConnection;pConnection = session.GetHttpConnection(strServer, wPort);

3、pConnection->OpenRequest

		//httpspConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("post.do"), NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE| INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);//httppConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("post.do"));

4、pFile->SendRequest(szHeaders, (LPVOID)reqchar, strlen(reqchar));

		pFile->SendRequest(szHeaders, (LPVOID)reqchar, strlen(reqchar));

5、pFile->QueryInfoStatusCode(dwRet)

https请求

			CString strURL = "https://209.144.91.204:443/";CString strServer, strObject;INTERNET_PORT wPort;DWORD dwType;if (!AfxParseURL(strURL, dwType, strServer, strObject, wPort)){return false;//URL解析错误}pConnection = session.GetHttpConnection(strServer, wPort);						//二、连接到Http服务器:if (NULL == pConnection){return false;}pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("/post.do"), NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE| INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);

http请求

			CString dnsUrl = ipStr + ":80";pConnection = session.GetHttpConnection(url);pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, ("/post.do"));

json解析

			int len = pFile->GetLength();char buf[2048];int numread;Json::Reader jsonReader;Json::Value root;while ((numread = pFile->Read(buf, sizeof(buf) - 1)) > 0){buf[numread] = '\0';strFile += buf;}if (log)AfxMessageBox(strFile);if (jsonReader.parse(buf, root)) {int retCode = root["retcode"].asInt();
http://www.lryc.cn/news/217079.html

相关文章:

  • UE5加载websocket模块为空
  • 学习 Python 数据可视化,如何快速入门?
  • XUbuntu22.04之simplenote支持的Markdown语法总结(一百九十一)
  • JAVA深化篇_26——Apache commons-io工具包的使用
  • centos 7 kafka2.6单机安装及动态认证SASL SCRAM配置
  • TrafficWatch 数据包嗅探器工具
  • MySQL Binlog实战应用之一
  • 【MySQL】MVCC机制(undo log,read view)
  • gma 2 教程(三)坐标参考系统:3.投影方法
  • 蓝桥杯每日一题2023.11.2
  • Leetcode67二进制求和
  • 线性代数 第五章 特征值与特征向量
  • Python嵌入式数据库 / 轻量级数据库 / 小型数据库介绍(SQLite、Pandas DataFrame、TinyDB)(python数据库)
  • USB PD v1.0快速充电通信原理
  • 【华为】路由器以PPPoE拨号接入广域网
  • Linux内核分析(一)--内核架构和子系统
  • 【PyQt学习篇 · ⑨】:QWidget -控件交互
  • 新版本IntelliJ IDEA(如2023)中运行Spring Boot找不到VM options进行端口的修改的问题解决
  • Swift语言配合HTTP写的一个爬虫程序
  • 【lvgl】linux开发板搭建环境
  • C之(10)CMocka-单元测试框架使用
  • 如何在idea中使用maven搭建tomcat环境
  • 单点登录
  • 大数据(十):数据可视化(二)
  • pytorch+LSTM实现使用单参数预测,以及多参数预测(代码注释版)
  • 腾讯云3年/5年特惠云服务器购买入口及攻略
  • 【Linux】jdk Tomcat MySql的安装及Linux后端接口部署
  • 天空卫士为集度智能汽车系上“安全带”
  • vue el-table-column 修改一整列的背景颜色
  • docker 安装 minio (单体架构)