在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
网上就是找不到这个C++版的MsMultiPartFormData,都是indy下的object pascal版本的。受不了了,我干脆自己写了个。呵呵,花了点时间,弄好了。弄好了才发现,对HTTP的POST请求包的格式好清楚了,呵呵,收获呀。 **************************************************************** MsMultiPartFormData.h
#pragma once class MsMultiPartFormData public: }; **************************************************************** MsMultiPartFormData.cpp
#include "StdAfx.h"
MsMultiPartFormData::MsMultiPartFormData(void) Boundary = GenerateUniqueBoundary(); MsMultiPartFormData::~MsMultiPartFormData(void) CString MsMultiPartFormData:: GenerateUniqueBoundary(void) void MsMultiPartFormData:: AddFormField(CString FieldName, CString FieldValue) void MsMultiPartFormData:: AddFile(CString FieldName,CString FileName,CString ContentType) //从本地文件中读取文件内容,进行上传 HRESULT hr=file.Create(FileName,GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING); if(FAILED(hr)) ULONGLONG filesize=0; file.GetSize(filesize); byte* buffer=new byte[filesize+1]; if(FAILED(hr)) file.Seek( 0, FILE_BEGIN ); if(FAILED(hr)) file.Close(); CString fileData; long index; field.Format(CRLF + DD + Boundary + CRLF + CONTENT_DISPOSITION +FILE_NAME_PLACE_HOLDER + CRLF + CONTENT_LENGTH +CONTENT_TYPE_PLACE_HOLDER+ContentType+CRLF+CRLF, FieldName, FileName, filesize); void MsMultiPartFormData:: PrepareStreamForDispatch() byte* MsMultiPartFormData:: GetFormData() int MsMultiPartFormData:: GetFormDataLengh() |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论