91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

在網上找的大都是多字節的工程代碼,傳參以及返回參數中有中文都會亂碼。現在VC工程幾乎都是Unicode字符集,這個類已經完全解決了中文亂碼問題,并且支持Get和Post請求,在VS2015下已經測試通過,注釋詳細,有使用示例。

資源截圖

代碼片段和文件信息

/************************************************************************
使用示例(測試網址是自己寫的WebService接口):
1.?get
CString?strUrl1;
strUrl1?=?L“http://192.168.2.179:9999/WebService1.asmx“;
strUrl1?+=?L“/ShowStringParam?userName=老王&userAge=42“;
std::string?strGetInfo1(““);
CWebCommand?webCommand1;
int?nRet1?=?webCommand1.HttpGet(strUrl1?strGetInfo1);
2.?post
CString?strUrl2;
strUrl2?=?L“http://192.168.2.179:9999/WebService1.asmx“;
strUrl2?+=?L“/ShowStringParam“;
std::string?strGetInfo2;
CWebCommand?webCommand2;
webCommand2.AddParam(_T(“userName“)?_T(“老王“));
webCommand2.AddParam(_T(“userAge“)?_T(“42“));
int?nRet2?=?webCommand2.HttpPost(strUrl2?strGetInfo2);
************************************************************************/
#include?“stdafx.h“
#include?“WebCommand.h“

#include?
#pragma?comment(lib?“Ws2_32.lib“)

#include?
#pragma?comment(lib?“comsuppw.lib“)
using?namespace?_com_util;

#define?CONNECTON_TIMEOUT 4000 //?超時標準

#define?BUFFER_SIZE???(4?*?1024) //?接收數據buffer?size

#define?NORMAL_CONNECT???INTERNET_FLAG_KEEP_CONNECTION
#define?SECURE_CONNECT???NORMAL_CONNECT?|?INTERNET_FLAG_SECURE
#define?NORMAL_REQUEST???INTERNET_FLAG_RELOAD?|?INTERNET_FLAG_DONT_CACHE
#define?SECURE_REQUEST???NORMAL_REQUEST?|?INTERNET_FLAG_SECURE?|?INTERNET_FLAG_IGNORE_CERT_CN_INVALID

CWebCommand::CWebCommand(LPCTSTR?strAgent)?:
m_pConnection(NULL)
m_pFile(NULL)
m_strPostData(““)
{
m_pSession?=?new?CInternetSession(strAgent);
}

CWebCommand::~CWebCommand()
{
Clear();

if?(NULL?!=?m_pSession)
{
m_pSession->Close();
delete?m_pSession;
m_pSession?=?NULL;
}
}

int?CWebCommand::HttpGet(CString?strUrl?string?&strResponse)
{
return?ExecuteGetRequest(strUrl?strResponse);
}

int?CWebCommand::HttpPost(CString?strUrl?string?&strResponse)
{
return?ExecutePostRequest(strUrl?strResponse);
}

void?CWebCommand::AddParam(CString?strName?CString?strVaule)
{
m_strPostData?=?m_strPostData?+?strName?+?_T(“=“)?+?strVaule?+?_T(“&“);
}

void?CWebCommand::Clear()
{
if?(NULL?!=?m_pFile)
{
m_pFile->Close();
delete?m_pFile;
m_pFile?=?NULL;
}

if?(NULL?!=?m_pConnection)
{
m_pConnection->Close();
delete?m_pConnection;
m_pConnection?=?NULL;
}
}

int?CWebCommand::ExecuteGetRequest(CString?strUrl?string?&?strResponse)
{
try
{
//?1.?首先得設置個超時標準吧
m_pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT?CONNECTON_TIMEOUT);

//?2.?request?to?the?HTTP?server
ConvertUnicodeToUtf8(strUrl); //?before?OpenUrl?convert?strUrl?coding
m_pFile?=?(CHttpFile*)m_pSession->OpenURL(strUrl);
if?(m_pFile)
{
char?szChars[BUFFER_SIZE?+?1]?=?{?0?}; //?buffer
UINT?nReaded?=?0; //?The?number?of?bytes?transferred?to?the?buffer
while?((nReaded?=?m_pFile->Read((void?*)szChars?BUFFER_SIZE))?>?0)
{
szChars[nReaded]?=?‘\0‘;
strResponse?+=?szChars;
}

ConvertUtf8ToUnicode(strRespons

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-31?08:57??WebCommand\
?????文件???????14248??2017-04-01?17:43??WebCommand\WebCommand.cpp
?????文件????????2748??2017-04-01?17:43??WebCommand\WebCommand.h

評論

共有 條評論