zoukankan      html  css  js  c++  java
  • Windows MFC HTTP 函数流程

    Windows MFC HTTP 函数流程

     1 //建立连接
     2 pInternetSession = new CInternetSession(AfxGetAppName());
     3 
     4 
     5 
     6 //根据HttpUr解析
     7 CString strServer;
     8 CString strObject;
     9 DWORD dwServiceType;
    10 INTERNET_PORT nPort;
    11 AfxParseURL(m_strHttpUrl, dwServiceType, strServer, strObject, nPort);
    12 
    13 
    14 
    15 //创建CHttpConnection对象
    16 pHttpConnection = pInternetSession->GetHttpConnection(strServer, nPort);
    17 
    18 
    19 
    20 //打开一个HTTP请求
    21 strTempObject = strObject + "?ccvid=%s&format=%s&time=%I64u"
    22 pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST/*HTTP_VERB_GET*/, strTempObject/*strObject*/);
    23 
    24 
    25 
    26 //添加发往HTTP服务器的请求头
    27 "Content-Type: application/x-www-form-urlencoded; charset=utf-8"
    28 pHttpFile->AddRequestHeaders(XXX);
    29 
    30 
    31 
    32 //向HTTP服务器发送请求
    33 pHttpFile->SendRequest(NULL, 0, strReq.GetBuffer(), strReq.GetLength());
    34 
    35 
    36 
    37 //读取HTTP服务器的响应
    38 while ((nReaded = pHttpFile->Read((void*)szChars, 1024)) > 0)
    39 {
    40 }
    41 
    42 
    43 
    44 //关闭CHttpFile、CHttpConnection、CInternetSession并释放其资源
    45 if (NULL != pHttpFile)
    46 {
    47     pHttpFile->Close();
    48     delete pHttpFile;
    49     pHttpFile = NULL;
    50 }
    51 if (NULL != pHttpConnection)
    52 {
    53     pHttpConnection->Close();
    54     delete pHttpConnection;
    55     pHttpConnection = NULL;
    56 }
    57 if (NULL != pInternetSession)
    58 {
    59     pInternetSession->Close();
    60     delete pInternetSession;
    61     pInternetSession = NULL;
    62 }
  • 相关阅读:
    OpenWrt配置绿联的usb转Ethernet网口驱动
    SQL_wm_concat函数实验:实现字段合并
    BingMap频繁Add Pushpin和Delete Pushpin会导致内存泄露
    比較C++和Java 二
    【JAVASE】Java同一时候抛出多个异常
    uva 1463
    Android 撕衣服(刮刮乐游戏)
    轻松掌握一致性哈希算法
    Oracle之sql语句优化
    Eclipse导出Library
  • 原文地址:https://www.cnblogs.com/diaoss/p/11583704.html
Copyright © 2011-2022 走看看