HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
来源:互联网 发布:c语言sleep没反应 编辑:程序博客网 时间:2024/05/16 17:44
玩过抓包,网络协议分析的朋友肯定都知道http https post get,web端和用户的交互主要是通过post get完成的。
今天带给大家的是C++版本的http https get post,只会易语言的朋友请移步。
我这里有两种实现:
1:libcurl实现的CHttpClient类,该类实现了Htpp和Https的get post方法。
2:winhttp实现的WinHttpClient类,同样也实现了Htpp和Https的get post方法。
看上去还不错吧!下面讲讲使用方法。
一:关于libcurl方式实现的CHttpClient注意事项。
1、ibcurl编译为静态库,代码生成选项,Debug版本请使用MTd,Release请使用MT。
2、预处理器请添加CURL_STATICLIB;
使用方法:
1、将curl文件夹和httpclient.h,httpclient.cpp拷贝到项目代码目录。
2、将项目目录下的httpclient.h,httpclient.cpp添加到项目中。
3、选中httpclient.cpp,不使用预编译头。
部署完成,使用如下
1、拷贝WinHttpClient文件夹到项目代码目录。
2、直接使用。
今天带给大家的是C++版本的http https get post,只会易语言的朋友请移步。
我这里有两种实现:
1:libcurl实现的CHttpClient类,该类实现了Htpp和Https的get post方法。
2:winhttp实现的WinHttpClient类,同样也实现了Htpp和Https的get post方法。
两者使用起来都很方便灵活。
// curlDemo.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#include <iostream>#include "WinHttpClient/WinHttpClient.h"#include "httpclient.h"using namespace std; wstring UTF8ToUnicode( const string &str ){ int len = 0; len = str.length(); int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, NULL, 0 ); wchar_t *pUnicode; pUnicode = new wchar_t[unicodeLen + 1]; memset(pUnicode, 0, (unicodeLen + 1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen ); wstring rt; rt = ( wchar_t * )pUnicode; delete pUnicode; return rt;} int _tmain(int argc, _TCHAR* argv[]){ string strResponse; //curl CHttpClient Test CHttpClient client; client.Get("http://www.baidu.com",strResponse); MessageBoxW(NULL,UTF8ToUnicode(strResponse).c_str(),L"http://www.baidu.com",MB_OK); strResponse.clear(); client.Gets("https://www.alipay.com",strResponse); MessageBoxW(NULL,UTF8ToUnicode(strResponse).c_str(),L"https://www.alipay.com",MB_OK); strResponse.clear(); client.Get("http://so.baiduyun.me/search.php?wd=google",strResponse); MessageBoxW(NULL,UTF8ToUnicode(strResponse).c_str(),L"http://so.baiduyun.me/search.php?wd=google",MB_OK); strResponse.clear(); client.Post("http://so.baiduyun.me/search.php","wd=google",strResponse); MessageBoxW(NULL,UTF8ToUnicode(strResponse).c_str(),L"http://so.baiduyun.me/search.php?wd=google",MB_OK); //winhttp WinHttpClient Test WinHttpClient WinClient(L"https://itunes.apple.com/cn/lookup?id=527563481"); WinClient.SetRequireValidSslCertificates(false); WinClient.SendHttpRequest(L"GET"); wstring httpResponseContent = WinClient.GetResponseContent(); MessageBoxW(NULL,httpResponseContent.c_str(),L"http://www.baidu.com",MB_OK); return 0;}运行部分效果图:
看上去还不错吧!下面讲讲使用方法。
一:关于libcurl方式实现的CHttpClient注意事项。
1、ibcurl编译为静态库,代码生成选项,Debug版本请使用MTd,Release请使用MT。
2、预处理器请添加CURL_STATICLIB;
使用方法:
1、将curl文件夹和httpclient.h,httpclient.cpp拷贝到项目代码目录。
2、将项目目录下的httpclient.h,httpclient.cpp添加到项目中。
3、选中httpclient.cpp,不使用预编译头。
部署完成,使用如下
#include "httpclient.h" string strResponse;//curl CHttpClient TestCHttpClient client;client.Get("http://www.baidu.com",strResponse);MessageBoxW(NULL,UTF8ToUnicode(strResponse).c_str(),L"http://www.baidu.com",MB_OK);
1、拷贝WinHttpClient文件夹到项目代码目录。
2、直接使用。
#include "WinHttpClient/WinHttpClient.h" //winhttp WinHttpClient TestWinHttpClient WinClient(L"https://itunes.apple.com/cn/lookup?id=527563481");WinClient.SetRequireValidSslCertificates(false);WinClient.SendHttpRequest(L"GET");wstring httpResponseContent = WinClient.GetResponseContent();MessageBoxW(NULL,httpResponseContent.c_str(),L"http://www.baidu.com",MB_OK);
完整Demo下载地址(VS2010项目):
http://download.csdn.net/detail/sunflover454/9170719 1 0
- HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
- HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
- HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- Linux命令发送Http的get或post请求(curl和wget两种方法)
- Linux命令发送Http的get或post请求(curl和wget两种方法)
- linux命令发送http的get或post请求(curl和wget两种方法)
- Linux命令发送Http的get或post请求(curl和wget两种方法)
- curl请求https POST和GET方法
- curl实现GET和POST
- cURL实现Get和Post
- CURL实现HTTP的GET POST方法
- CURL封装的php http和https请求网页模拟post get函数
- java封装httpClient工具(支持http和https,包含get和post请求)
- http https get post
- php的curl实现get和post
- poj 3667 Hotel(线段树)
- 求最大值(qduoj)QDU创新实验室第二次月赛B题
- android开发学习——序
- LeetCode-Contains Duplicate II
- 对Xcode7真机调试的无力吐槽
- HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
- leetcode之H-Index
- GIT@OSC源码分析之AppManager(1)
- poj 3241 Object Clustering (曼哈顿距离最小生成树)
- 关于白盒测试的实验总结
- 同步函数
- Android之ANR异常及解决方法
- js中定义类的方法
- POJ 2398 Toy Storage 线段相交