資源簡介
玩過抓包,網(wǎng)絡(luò)協(xié)議分析的朋友肯定都知道http https post get,web端和用戶的交互主要是通過post get完成的。
我這里有兩種實現(xiàn):
1:libcurl實現(xiàn)的CHttpClient類,該類實現(xiàn)了Htpp和Https的get post方法。
2:winhttp實現(xiàn)的WinHttpClient類,同樣也實現(xiàn)了Htpp和Https的get post方法。
兩者使用起來都很方便靈活。
詳細說明:
http://blog.csdn.net/sunflover454/article/details/49030803
代碼片段和文件信息
//?curlDemo.cpp?:?定義控制臺應(yīng)用程序的入口點。
//
#include?“stdafx.h“
#include?
#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(NULLUTF8ToUnicode(strResponse).c_str()L“http://www.baidu.com“MB_OK);
strResponse.clear();
client.Gets(“https://www.alipay.com“strResponse);
MessageBoxW(NULLUTF8ToUnicode(strResponse).c_str()L“https://www.alipay.com“MB_OK);
strResponse.clear();
? client.Get(“http://so.baiduyun.me/search.php?wd=google“strResponse);
MessageBoxW(NULLUTF8ToUnicode(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(NULLUTF8ToUnicode(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(NULLhttpResponseContent.c_str()L“http://www.baidu.com“MB_OK);
return?0;
}
評論
共有 條評論