資源簡介
此HTTP類使用C++編寫,用Socket技術實現HTTP,直接在成熟商業項目中抽取出來的,經過了多年的使用和改善,已經非常穩定,是學習Socket和HTTP的優秀資源,同時也是可以直接拿去在實際項目中的使用模塊。
功能:
1.實現了HTTP的GET、POST操作。
2.自動管理Cookies,也可以通過接口控制Cookies。
3.自動進行編碼轉換。
說明:
1.使用此類之前必須調用Init接口進行初始化。
2.如果中文出現亂碼,請在調用Get、Post之前調用SetCodePage設置編碼。
3.如需要封裝好的HTTPS、異步HTTP、完成端口TCP等商業源碼,請聯系作者。

代碼片段和文件信息
#include?“StdAfx.h“
#include?“CodePageConvert.h“
/******************************************************************************
把源串轉換為寬字符串
******************************************************************************/
bool?MBToWC(wstring?&?strWC?string?strSrc?UINT?uiSrcCodePage)
{
//獲取轉換為寬字符編碼所需的長度
if?(strSrc?==?““)
{
strWC?=?L““;
return?true;
}
int?nNeedSizeWC?=?MultiByteToWideChar(uiSrcCodePage?0
?strSrc.c_str()?-1?NULL?0);
if?(nNeedSizeWC?<=?0)
{
return?false;
}
//分配足夠的字符串空間,減去結束符
strWC.resize(nNeedSizeWC?-?1);
//進行轉換
if?((int)strWC.size()? {
return?false;
}
int?nSizeWC?=?MultiByteToWideChar(uiSrcCodePage?0
?strSrc.c_str()?-1
?(LPWSTR)strWC.c_str()?nNeedSizeWC);
if?(nSizeWC?<=?0)
{
return?false;
}
return?true;
}
/******************************************************************************
把寬字符串轉換為目標串
******************************************************************************/
bool?WCToMB(string?&?strDst?wstring?strWC?UINT?uiDstCodePage)
{
//獲取轉換為目標字符編碼所需的長度
if?(strWC?==?L““)
{
strDst?=?““;
return?true;
}
int?nNeedSizeMB?=?WideCharToMultiByte(uiDstCodePage?0
?strWC.c_str()?-1?NULL?0?NULL?NULL);
if?(nNeedSizeMB?<=?0)
{
return?false;
}
//分配足夠的字符串空間
strDst.resize(nNeedSizeMB?-?1);
//進行轉換
if?((int)strDst.size()? {
return?false;
}
int?nSizeA?=?WideCharToMultiByte(uiDstCodePage?NULL?strWC.c_str()
?-1?(LPSTR)strDst.c_str()?nNeedSizeMB?NULL?NULL);
if?(nSizeA?<=?0)
{
return?false;
}
return?true;
}
/******************************************************************************
把源串轉換為目標串
******************************************************************************/
bool?MBToMB(string?&?strTrans
?UINT?uiDstCodePage?UINT?uiSrcCodePage)
{
//先把源串轉換為寬字符串
if?(strTrans?==?““)
{
return?true;
}
wstring?strWC?=?L““;
if?(!MBToWC(strWC?strTrans?uiSrcCodePage))
{
return?false;
}
if?(strWC?==?L““)
{
return?false;
}
//再把寬字符串轉換為目標串
if?(!WCToMB(strTrans?strWC?uiDstCodePage))
{
return?false;
}
if?(strTrans?==?““)
{
return?false;
}
return?true;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1229??2013-11-13?15:49??CodePageConvert.h
?????文件???????1141??2013-05-10?22:21??CriticalLock.cpp
?????文件????????989??2015-10-28?18:22??CriticalLock.h
?????文件???????4845??2014-06-14?09:29??DNSMap.cpp
?????文件???????3094??2015-10-28?18:25??DNSMap.h
?????文件???????1066??2013-05-05?17:19??DNSMapTypes.h
????I.A....?????39947??2015-10-28?18:25??HTTP.cpp
?????文件??????19032??2015-10-28?20:59??HTTP.h
?????文件???????4234??2015-10-28?18:19??HTTPTypes.h
?????文件???????2389??2014-07-01?13:02??CodePageConvert.cpp
-----------?---------??----------?-----??----
????????????????77966????????????????????10
- 上一篇:C語言實現Cat程序
- 下一篇:通信中數據分段與重組算法設計及其源碼實現
評論
共有 條評論