CHttpConnection的使用



1.构造一个CInternetSession的实例

CInternetSession*   pSession =new CinternetSession();
     //CInternetSession m_session;//类成员变量可不new




2.构造一个CHttpConnection对象

CHttpConnection* pConnection = pSession->GetHttpConnection(csServerName);
     //csServerName 域名:如:www.baidu.com




3.打开HTTP连接

CHttpFile* pHttpFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, csObjectName);
//csObjectName网址的后面部分




4.发送数据

BOOL bresult = pHttpFile->SendRequest(csHeaders, (LPVOID)(LPCTSTR)pCharFormData, strlen(pCharFormData));




5.读取服务器返回的数据

char strReSult[1024];
memset(strReSult, 0, BUFFER_SIZE);
while (pHttpFile->Read(strReSult, 1023))
{
}




6.关闭连接,释放资源

pHttpFile->Close();
pConnection->Close() ;
delete  pSession;




网络:

InternetOpen
HttpOpenRequest
HttpAddRequestHeaders
InternetCloseHandle
HttpSendRequest
HttpQueryInfo


你可能感兴趣的:(C++)