• 大小: 16KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-25
  • 语言: C/C++
  • 标签: HTTP  Socket  VC  C++  

资源简介

此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() < nNeedSizeWC - 1)
{
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() < nNeedSizeMB - 1)
{
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


评论

共有 条评论