首页 > 其他分享 >MFC通过Http请求上传文件

MFC通过Http请求上传文件

时间:2024-04-09 14:11:08浏览次数:32  
标签:MFC Http pFile CString pHttpFile Close NULL 上传 INTERNET

MFC通过Http请求上传文件

void CMFCApplication1Dlg::HttpPostFile(string url, CString file, string paramName, string contentType)
{

CInternetSession pSession(_T("ic_PostWav")); //可以随意
CHttpConnection* pConnect;
CHttpFile * pFile;

//通过 url解析出来
CString pServeIP = _T("127.0.0.1");
INTERNET_PORT wPort = 8888;
CString pObject = _T("/api/v1/documents/upload");

pConnect = pSession.GetHttpConnection(pServeIP, wPort);
pFile = pConnect->OpenRequest(CHttpConnection::HTTP_VERB_POST, pObject, NULL, 0, NULL, NULL, INTERNET_FLAG_DONT_CACHE);

string boundary = "----1a2b3c4d5e6f";
//Http 头部
string pPostHeader;
pPostHeader = "Accept:audio/x-wav,text/html,application/xhtml+xml,application/xml,*/*;q=0.9,*/*;q=0.8\r\n";
pPostHeader += "Content-Type: multipart/form-data;";
pPostHeader += "boundary=" + boundary + "\r\n";
pPostHeader += "Connection: keep-alive\r\n";
CString httpHead;
httpHead.Format(_T("%s"), pPostHeader);
pFile->AddRequestHeaders(httpHead);

//数据帧头
string dataTop, name,filename;
name = "name";
filename = "filename";

dataTop = "--"+ boundary +"\r\n";
dataTop += "Content-Disposition:form-data;";
dataTop += "name=\"" + name + "\";";
dataTop += "filename=\"" + filename + "\"\r\n";
dataTop += "Content-Type:" + contentType + "\r\n\r\n";

//byte* pPostTopbytes = new byte[dataTop.length()]; //todo
//for (int i = 0; i < dataTop.length();i++)
//{
// pPostTopbytes[i] = (byte)dataTop[i];
//}

byte* pPostTopbytes = (byte*)dataTop.c_str();

//数据包尾
string dataEnd;
dataEnd = "\r\n--" + boundary + "--\r\n";
//byte* enderbyte = new byte[ dataEnd.size()]; //todo
//for (int i = 0; i < dataEnd.length(); i++)
//{
// enderbyte[i] = (byte)dataEnd[i];
//}

byte* enderbyte = (byte*)dataEnd.c_str();


CFile cfile;
cfile.Open(file, CFile::modeRead | CFile::shareDenyRead, NULL);

DWORD dwSize = dataTop.length() + dataEnd.length() + cfile.GetLength();
pFile->SendRequestEx(dwSize);

//写数据头
pFile->Write(pPostTopbytes, dataTop.length());

//写数据主体
int bufflength = 4 * 1024;
byte* buffer = new byte[bufflength];
int byteRead = 0;
while ((byteRead = cfile.Read(buffer, bufflength)) != 0)
{
pFile->Write(buffer, byteRead);
}
cfile.Close();

//写数据尾部
pFile->Write(enderbyte, dataEnd.length() );
//发送文件
pFile->EndRequest();

//接收返回
CString strSentence = _T(""), strGetSentence = _T("");
DWORD dwRet;
pFile->QueryInfoStatusCode(dwRet);
if (HTTP_STATUS_OK == dwRet)
{
while (pFile->ReadString(strSentence)) // 读取提交数据后的返回结果
{
strGetSentence = strGetSentence + strSentence;
}
char * temp = (char*)strGetSentence.GetBuffer(strGetSentence.GetLength());
string reponce(temp);
//todo: 将返回的编码数据转为自己需要的编码数据
}
pFile->Close();
pConnect->Close();
}

void CMFCApplication1Dlg::OnBnClickedOk()
{
//调用方式
HttpPostFile("", L"E:\\123\\内墙With柱fbx.pcx"/*L"E:\\123\\test.txt"*/, "uploadeFile", "application/octet-stream" /*L"text/plain"*/);
}


MFC中发送HTTP或HTTPS请求

 

基本知识

HTTP(超文本传输协议)
HTTPS(超文本传输安全协议)
URL(统一资源定位器)

例子

1. 一个简单的例子

复制代码
#include <afxinet.h>
#include <string>

bool testHttp(const CString& strUrl, const BYTE* data, int nBytes, CString& strReceive)
{
    // 解析Url
    // 例如:https://www.cnblogs.com/Zender/p/7596730.html
    DWORD dwServiceType;        // 协议类型:http/https    AFX_INET_SERVICE_HTTP (3)    AFX_INET_SERVICE_HTTPS (4107)
    CString strServer;            // Host    例如:www.cnblogs.com 或者 192.168.10.9
    CString strObject;            // other   例如:/Zender/p/7596730.html
    INTERNET_PORT wPort;        // 端口号   http的默认端口号是80,https的默认端口号是443
    if (!AfxParseURL(strUrl, dwServiceType, strServer, strObject, wPort))
    {
        //解析Url失败
        return false;
    }
    CInternetSession session; // 创建会话
    const int nTimeOut = 10 * 1000;  // 超时设置为 10s
    session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut);
    session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 2);
    CHttpConnection* pConn = NULL;
    CHttpFile* pFile = NULL;
    if (AFX_INET_SERVICE_HTTP == dwServiceType)
    {
        pConn = session.GetHttpConnection(strServer, wPort);
        pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);
    }
    else if (AFX_INET_SERVICE_HTTPS == dwServiceType)
    {
        pConn = session.GetHttpConnection(strServer, INTERNET_FLAG_SECURE, wPort);
        pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject, NULL, 1, NULL, NULL,
            INTERNET_FLAG_SECURE | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD |
            INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID);//SECURITY_FLAG_IGNORE_UNKNOWN_CA
    }
    else
    {
        //其他协议返回
        return false;
    }
    try
    {
        CString strHeaders("Content-Type: application/x-www-form-urlencoded");//请求头
        BOOL bRet = pFile->SendRequest(strHeaders, (LPVOID)data, nBytes);
        if (!bRet)
        {
            goto Failure_label;
        }
        DWORD dwStatusCode;
        bRet = pFile->QueryInfoStatusCode(dwStatusCode);
        if (HTTP_STATUS_OK != dwStatusCode)//#define HTTP_STATUS_OK  200
        {
            CString strErrInfo;
            pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS, strErrInfo);
            goto Failure_label;
        }
        std::string sReceive;
        char buffer[1024] = { 0 };
        for (UINT len = 0; (len = pFile->Read(buffer, sizeof(buffer))) > 0; memset(buffer, 0, sizeof(buffer)))
        {
            std::string s(buffer, len);
            sReceive += s;
        }
        strReceive = CStringA(sReceive.c_str(), sReceive.length());//注意:若sReceive中有\0,可能会截断
        return true;
    }
    catch (CInternetException& e)
    {
        TCHAR szErr[512] = { 0 };
        e.GetErrorMessage(szErr, sizeof(szErr));
        CString strErrInfo;
        pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS, strErrInfo);
        goto Failure_label;
    }

Failure_label:
    if (pConn)
    {
        pConn->Close();
        delete pConn;
        pConn = NULL;
    }
    if (pFile)
    {
        pFile->Close();
        delete pFile;
        pFile = NULL;
    }
    return false;
}
BOOL CtestMFCHttpApp::InitInstance()
{
    CString url("https://www.cnblogs.com/12Zender/p/7596730.html");
    CString strReceive;
    BYTE* data = (BYTE*)"123";
    testHttp(url,data,3,strReceive);
}
复制代码

2. 网上别人封装的类(MFC - HTTP(post与get)请求网页内容或图片

复制代码
/////////////////  CHttpClient.h //////////////

#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H
 
#include <afxinet.h>
 
#define  IE_AGENT  _T("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)")
#define  REQ_CODE_UTF8  _T("UTF-8")
#define  REQ_CODE_GBK   _T("GBK")
 
// 操作成功
#define SUCCESS        0
// 操作失败
#define FAILURE        1
// 操作超时
#define OUTTIME        2
 
class CHttpClient
{
public:
    CHttpClient(const CString& szReqCode = REQ_CODE_UTF8,LPCTSTR strAgent = IE_AGENT);
    virtual ~CHttpClient(void);
 
    int HttpGet(LPCTSTR strUrl, CString &strResponse);
    int HttpGetImg(LPCTSTR strUrl, LPCTSTR imgPath);
    int HttpPost(LPCTSTR strUrl, CString &strResponse, LPCTSTR strPostData);
 
private:
    int ExecuteRequest(LPCTSTR strMethod, LPCTSTR strUrl, LPCTSTR strPostData, CString &strResponse, LPCTSTR imgPath);
    void Clear();
    CStringA GetReqData(const CString&  szReqData);
    CString  GetResData(const CStringA& szResData);
private:
    CInternetSession *m_pSession;
    CHttpConnection *m_pConnection;
    CHttpFile *m_pFile;
    CString m_szReqCode;
};
 
#endif



///////////////////// CHttpClient.cpp  ///////////////////
////////////////////////////////// HttpClient.cpp
#include "StdAfx.h"
#include "HttpClient.h"
 
#define  BUFFER_SIZE       1024
 
#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| \
                                    INTERNET_FLAG_IGNORE_CERT_DATE_INVALID 
 
CHttpClient::CHttpClient(const CString& szReqCode,LPCTSTR strAgent)
{
    m_pSession = new CInternetSession(strAgent);
    m_szReqCode = szReqCode;
    m_pConnection = NULL;
    m_pFile = NULL;
}
 
CHttpClient::~CHttpClient(void)
{
    Clear();
    if (NULL != m_pSession)
    {
        m_pSession->Close();
        delete m_pSession;
        m_pSession = NULL;
    }
}
 
void CHttpClient::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 CHttpClient::ExecuteRequest(LPCTSTR strMethod, LPCTSTR strUrl, LPCTSTR strPostData, CString &strResponse, LPCTSTR imgPath = NULL)
{
    DWORD dwFlags;
    CString strServer;
    CString strObject;
    DWORD dwServiceType;
    INTERNET_PORT nPort;
    strResponse = _T("");
 
 
    AfxParseURL(strUrl, dwServiceType, strServer, strObject, nPort);
 
    if (AFX_INET_SERVICE_HTTP != dwServiceType && AFX_INET_SERVICE_HTTPS != dwServiceType)
    {
        return FAILURE;
    }
    try
    {
        m_pConnection = m_pSession->GetHttpConnection(strServer,
            dwServiceType == AFX_INET_SERVICE_HTTP ? NORMAL_CONNECT : SECURE_CONNECT,nPort);
        m_pFile = m_pConnection->OpenRequest(strMethod, strObject, NULL, 1, NULL, NULL,
            (dwServiceType == AFX_INET_SERVICE_HTTP ? NORMAL_REQUEST : SECURE_REQUEST));
        if (AFX_INET_SERVICE_HTTPS == dwServiceType)
        {
            m_pFile->QueryOption(INTERNET_OPTION_SECURITY_FLAGS, dwFlags);
            dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
            m_pFile->SetOption(INTERNET_OPTION_SECURITY_FLAGS, dwFlags);
        }
        m_pFile->AddRequestHeaders(_T("Accept: *,*/*"));
        m_pFile->AddRequestHeaders(_T("Accept-Language: zh-cn"));
        m_pFile->AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded"));
        m_pFile->AddRequestHeaders(_T("Accept-Encoding: deflate"));
        if (strPostData != NULL) {
            CStringA strData = GetReqData(strPostData);
            m_pFile->SendRequest(NULL, 0, (LPVOID)(LPCSTR)strData, strlen(strData));
        }
        else {
            m_pFile->SendRequest();
        }
        
        char szChars[BUFFER_SIZE + 1] = { 0 };
        CStringA strRawResponse = "";
        UINT nReaded = 0;
 
        if (imgPath == NULL) {
            while ((nReaded = m_pFile->Read((void*)szChars, BUFFER_SIZE)) > 0)
            {
                szChars[nReaded] = '\0';
                strRawResponse += szChars;
                memset(szChars, 0, BUFFER_SIZE + 1);
            }
            strResponse = GetResData(strRawResponse);
        } else {
            CFile f;
            f.Open(imgPath, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
            while ((nReaded = m_pFile->Read((void*)szChars, BUFFER_SIZE)) > 0)
            {
                szChars[nReaded] = '\0';
                f.Write(szChars, BUFFER_SIZE);
                memset(szChars, 0, BUFFER_SIZE + 1);
            }
            f.Close();
        }
        Clear();
    }
    catch (CInternetException* e)
    {
        Clear();
        DWORD dwErrorCode = e->m_dwError;
        e->Delete();
        DWORD dwError = GetLastError();
 
        if (ERROR_INTERNET_TIMEOUT == dwErrorCode)
        {
            return OUTTIME;
        }
        else
        {
            return FAILURE;
        }
    }
    return SUCCESS;
}
 
int CHttpClient::HttpGet(LPCTSTR strUrl, CString &strResponse)
{
    return ExecuteRequest(_T("GET"), strUrl, NULL, strResponse);
}
 
int CHttpClient::HttpPost(LPCTSTR strUrl, CString &strResponse, LPCTSTR strPostData)
{
    return ExecuteRequest(_T("POST"), strUrl, strPostData, strResponse);
}
 
int CHttpClient::HttpGetImg(LPCTSTR strUrl, LPCTSTR imgPath)
{
    CString str;
    return ExecuteRequest(_T("GET"), strUrl, NULL, str,imgPath);
}
CStringA CHttpClient::GetReqData(const CString& szReqData)
{
    // 预算-缓冲区中多字节的长度    
    int ansiiLen = WideCharToMultiByte(CP_UTF8, 0, szReqData, -1, NULL, 0, NULL, NULL);
    char * pAssii = (char*)malloc(sizeof(char)*ansiiLen);
    // 开始向缓冲区转换字节    
    WideCharToMultiByte(CP_UTF8, 0, szReqData, -1, pAssii, ansiiLen, NULL, NULL);
    CStringA szRet(pAssii);
    free(pAssii);
    return szRet;
}
CString CHttpClient::GetResData(const CStringA& szResData)
{
    if (m_szReqCode == REQ_CODE_GBK)
        return CString(szResData);
    // 预算-缓冲区中宽字节的长度    
    int unicodeLen = MultiByteToWideChar(CP_UTF8, 0, szResData, -1, NULL, 0);
    wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
    // 开始向缓冲区转换字节    
    MultiByteToWideChar(CP_UTF8, 0, szResData, -1, pUnicode, unicodeLen);
    CString szRet(pUnicode);
    free(pUnicode);
    return szRet;
}




///////////////////// 使用方法  ///////////////////
    CHttpClient http;
    CString url;
    GetDlgItemText(IDC_EDIT2, url);
    CString str;
    http.HttpGet(url, str);
    AfxMessageBox(str);
复制代码

 

 

 

转载:https://www.cnblogs.com/Ray-chen/archive/2011/12/14/2287812.html

一、建立会话(Session)对象:

       CInternetSession mysession;

二、连接到Http服务器:

      CHttpConnection *myconn=mysession.GetHttpConnection("www.baidu.com");

三、打开Http请求:

      CHttpFile *myfile=myconn->OpenRequest("GET","/index.html");

四、发送Http请求:

      myfile->SendRequest();

五、从服务器读取字节流(bytes):

      CString mystr;
      CString tmp;
      while(myfile->ReadString(tmp))
      {
           mystr+=tmp;
      }

六、释放资源:

     myfile->Close();
      myconn->Close();
     mysession.Close();
     delete myfile;
     delete myconn;
     myfile=0;
     myconn=0;

     步骤基本如上,上例各函数参数主要使用默认参数,具体函数声明请查阅MSDN。另外别忘了异常处理!

1、下载文件
Download(const CString& strFileURLInServer, //待下载文件的URL
const CString & strFileLocalFullPath)//存放到本地的路径
{
 ASSERT(strFileURLInServer != "");
 ASSERT(strFileLocalFullPath != "");
 CInternetSession session;
 CHttpConnection* pHttpConnection = NULL;
 CHttpFile* pHttpFile = NULL;
 CString strServer, strObject;
 INTERNET_PORT wPort;

 

 DWORD dwType;
 const int nTimeOut = 2000;
 session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //重试之间的等待延时
 session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 1);   //重试次数
 char* pszBuffer = NULL;  

 

 try
 {
  AfxParseURL(strFileURLInServer, dwType, strServer, strObject, wPort);
  pHttpConnection = session.GetHttpConnection(strServer, wPort);
  pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);
  if(pHttpFile->SendRequest() == FALSE)
   return false;
  DWORD dwStateCode;

 

  pHttpFile->QueryInfoStatusCode(dwStateCode);
  if(dwStateCode == HTTP_STATUS_OK)
  {
    HANDLE hFile = CreateFile(strFileLocalFullPath, GENERIC_WRITE,
         FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
         NULL);  //创建本地文件
   if(hFile == INVALID_HANDLE_VALUE)
   {
    pHttpFile->Close();
    pHttpConnection->Close();
    session.Close();
    return false;
   }
 
   char szInfoBuffer[1000];  //返回消息
   DWORD dwFileSize = 0;   //文件长度
   DWORD dwInfoBufferSize = sizeof(szInfoBuffer);
   BOOL bResult = FALSE;
   bResult = pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,
           (void*)szInfoBuffer,&dwInfoBufferSize,NULL);

 

   dwFileSize = atoi(szInfoBuffer);
   const int BUFFER_LENGTH = 1024 * 10;
   pszBuffer = new char[BUFFER_LENGTH];  //读取文件的缓冲
   DWORD dwWrite, dwTotalWrite;
   dwWrite = dwTotalWrite = 0;
   UINT nRead = pHttpFile->Read(pszBuffer, BUFFER_LENGTH); //读取服务器上数据

 

   while(nRead > 0)
   {
    WriteFile(hFile, pszBuffer, nRead, &dwWrite, NULL);  //写到本地文件
    dwTotalWrite += dwWrite;
    nRead = pHttpFile->Read(pszBuffer, BUFFER_LENGTH);
   }

 

   delete[]pszBuffer;
   pszBuffer = NULL;
   CloseHandle(hFile);
  }
  else
  {
   delete[]pszBuffer;
   pszBuffer = NULL;
   if(pHttpFile != NULL)
   {
    pHttpFile->Close();
    delete pHttpFile;
    pHttpFile = NULL;
   }
   if(pHttpConnection != NULL)
   {
    pHttpConnection->Close();
    delete pHttpConnection;
    pHttpConnection = NULL;
   }
   session.Close();
    return false;
  }
 }
 catch(...)
 {
  delete[]pszBuffer;
  pszBuffer = NULL;
  if(pHttpFile != NULL)
  {
   pHttpFile->Close();
   delete pHttpFile;
   pHttpFile = NULL;
  }
  if(pHttpConnection != NULL)
  {
   pHttpConnection->Close();
   delete pHttpConnection;
   pHttpConnection = NULL;
  }
  session.Close();
  return false;
 }

 

 if(pHttpFile != NULL)
  pHttpFile->Close();
 if(pHttpConnection != NULL)
  pHttpConnection->Close();
 session.Close();
 return true;
}

2、上传文件
bool Download(const CString& strFileURLInServer, //待下载文件的URL
const CString & strFileLocalFullPath)//存放到本地的路径
{
ASSERT(strFileURLInServer != "");
ASSERT(strFileLocalFullPath != "");
CInternetSession session;
CHttpConnection* pHttpConnection = NULL;
CHttpFile* pHttpFile = NULL;
CString strServer, strObject;
INTERNET_PORT wPort;
bool bReturn = false;

DWORD dwType;
const int nTimeOut = 2000;
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //重试之间的等待延时
session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 1); //重试次数
char* pszBuffer = NULL;

try
{
AfxParseURL(strFileURLInServer, dwType, strServer, strObject, wPort);
pHttpConnection = session.GetHttpConnection(strServer, wPort);
pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);
if(pHttpFile->SendRequest() == FALSE)
return false;
DWORD dwStateCode;

pHttpFile->QueryInfoStatusCode(dwStateCode);
if(dwStateCode == HTTP_STATUS_OK)
{
HANDLE hFile = CreateFile(strFileLocalFullPath, GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
NULL); //创建本地文件
if(hFile == INVALID_HANDLE_VALUE)
{
pHttpFile->Close();
pHttpConnection->Close();
session.Close();
return false;
}

char szInfoBuffer[1000]; //返回消息
DWORD dwFileSize = 0; //文件长度
DWORD dwInfoBufferSize = sizeof(szInfoBuffer);
BOOL bResult = FALSE;
bResult = pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,
(void*)szInfoBuffer,&dwInfoBufferSize,NULL);

dwFileSize = atoi(szInfoBuffer);
const int BUFFER_LENGTH = 1024 * 10;
pszBuffer = new char[BUFFER_LENGTH]; //读取文件的缓冲
DWORD dwWrite, dwTotalWrite;
dwWrite = dwTotalWrite = 0;
UINT nRead = pHttpFile->Read(pszBuffer, BUFFER_LENGTH); //读取服务器上数据

while(nRead > 0)
{
WriteFile(hFile, pszBuffer, nRead, &dwWrite, NULL); //写到本地文件
dwTotalWrite += dwWrite;
nRead = pHttpFile->Read(pszBuffer, BUFFER_LENGTH);
}

delete[]pszBuffer;
pszBuffer = NULL;
CloseHandle(hFile);
bReturn = true;
}
}
catch(CInternetException* e)
{
TCHAR tszErrString[256];
e->GetErrorMessage(tszErrString, ArraySize(tszErrString));
TRACE(_T("Download XSL error! URL: %s,Error: %s"), strFileURLInServer, tszErrString);
e->Delete();
}
catch(...)
{
}

if(pszBuffer != NULL)
{
delete[]pszBuffer;
}
if(pHttpFile != NULL)
{
pHttpFile->Close();
delete pHttpFile;
}
if(pHttpConnection != NULL)
{
pHttpConnection->Close();
delete pHttpConnection;
}
session.Close();
return bReturn;

 

******************

 

标签:MFC,Http,pFile,CString,pHttpFile,Close,NULL,上传,INTERNET
From: https://www.cnblogs.com/ioriwellings/p/16071113.html

相关文章

  • 【SpringBoot整合系列】SpringBoot 实现大文件分片上传、断点续传及秒传
    目录功能介绍文件上传分片上传秒传断点续传相关概念相关方法大文件上传流程前端切片处理逻辑后端处理切片的逻辑流程解析后端代码实现功能目标1.建表SQL2.引入依赖3.实体类4.响应模板5.枚举类6.自定义异常7.工具类8.Controller层9.FileService10.LocalStorageService11......
  • Django后端如何限制上传文件大小
    在Django中,对上传文件大小进行限制可以通过几种不同的方法来实现。这包括在表单层面、视图层面或通过设置Django项目的全局配置。以下是一些常用的方法:方法1:使用Django设置限制文件大小在Django的settings.py文件中,你可以设置DATA_UPLOAD_MAX_MEMORY_SIZE来限制上传文件的大......
  • Firefox火狐浏览器控制台,提示:已拦截跨源请求:同源策略禁止读取位于 http://127.0.0.1
    前言全局说明Firefox火狐浏览器控制台,提示:已拦截跨源请求一、火狐官方说明https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin?utm_source=devtools&utm_medium=firefox-cors-errors&utm_campaign=default二、修改浏览器方法[原文......
  • 0day 新视窗新一代物业管理系统RegisterManager存在任意文件上传漏洞
     0x01阅读须知        技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用......
  • 致远OA fileUpload.do接口处存在任意文件上传漏洞
     0x01阅读须知        技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用......
  • [网络/HTTPS/Java] PKI公钥基础设施体系:基础概念篇
    0序看过上一篇文章、且有点懵的朋友,可以参看本篇————针对PKI体系的核心概念进行解释。1PKI体系(公开密钥基础设施体系)1.1PKI体系是什么?PKI是PublicKeyInfrastructure的缩写,中文叫做公开密钥基础设施,也就是利用公开密钥机制建立起来的基础设施。PKI的主要......
  • 电脑出现mfc140u.dll丢失怎么办?教你7个方法解决此问题
    mfc140u.dll是一个动态链接库(DynamicLinkLibrary,DLL)文件,它是MicrosoftWindows操作系统环境下用于支持应用程序运行的重要组成部分。具体来说,mfc140u.dll是MicrosoftFoundationClass(MFC)库14.0版本的Unicode版本动态链接库文件。 一、MFC140u.dll......
  • 在GitHub上用HTTP端口使用ssh
    问题:在实现本地仓库与GitHub仓库相关联时出现下图问题尝试了很多方法包括但不限于:更改公私钥密码,更改防火墙,检查仓库UPL等方法但都没有效果解决方法:通过HTTPS端口使用SSH测试有时,防火墙完全拒绝允许SSH连接。如果无法使用带有凭据缓存的HTTPS克隆,则可以尝试使用通过......
  • 【Azure App Service】验证App Service接受HTTP 2.0请求
    问题描述在AppService中启用了HTTP2.0后,如何来验证它可以正常接受HTTP2.0的请求呢?问题解答如果直接使用浏览器访问,无法直接判断出来是否使用HTTP2.0,所以本文中使用.NETConsole代码来测试HTTP2.0.第一步:打开VisualStudio2022,创建一个.NETConsoleApplication第二步......
  • http免费升级https
    背景:首先我们需要了解HTTPS并不是一个全新的协议,而是在HTTP的基础上,通过SSL增加了一层加密协议,从而大大增加了HTTP协议的安全性。HTTPS主要由两部分组成:HTTP(超文本传输协议)+SSL/TLS(安全协议),也就是在HTTP上又加了一层处理加密信息的模块。目录背景:http的概念和......