15,979
社区成员
发帖
与我相关
我的任务
分享
if (FALSE == fTrack.Open(pThis->_mFilePath, CFile::modeRead | CFile::shareDenyWrite))//读出文件
{
pThis->strError += _T("Unable to open the file.");
return nSuccess;
}
strHTTPBoundary = _T("---------------------------7b4a6d158c9");//定义边界值
strPreFileData = pThis->MakePreFileData(strHTTPBoundary, pcmname);
strPostFileData = pThis->MakePostFileData(strHTTPBoundary);
dwTotalRequestLength = strPreFileData.GetLength() + strPostFileData.GetLength() + fTrack.GetLength();//计算整个包的总长度
dwChunkLength = 16 * 1024;
pBuffer = malloc(dwChunkLength);
if (NULL == pBuffer)
{
return nSuccess;
}
try
{
char strProxyList[MAX_PATH], strUsername[64], strPassword[64];
strcpy(strProxyList, "10.168.166.205:808");
strcpy(strUsername, "fengrongxing");
strcpy(strPassword, "123456");
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy = strProxyList;
proxyinfo.lpszProxyBypass = NULL;
Session.SetOption(INTERNET_OPTION_PROXY, (LPVOID)&proxyinfo, sizeof(INTERNET_PROXY_INFO));
pHttpConnection = Session.GetHttpConnection(defServerName,nPort);
pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, defObjectName);
//取得HttpFile对象
pHttpFile->SetOption(INTERNET_OPTION_PROXY_USERNAME, strUsername, strlen(strUsername)+1);
pHttpFile->SetOption(INTERNET_OPTION_PROXY_PASSWORD, strPassword, strlen(strPassword)+1);
pHttpFile->AddRequestHeaders(pThis->MakeRequestHeaders(strHTTPBoundary));//发送包头请求
pHttpFile->SendRequestEx(dwTotalRequestLength, HSR_SYNC | HSR_INITIATE);
pHttpFile->Write((LPSTR)(LPCSTR)strPreFileData, strPreFileData.GetLength());//写入服务器所需信息
dwReadLength = -1;
while (0 != dwReadLength)
{
dwReadLength = fTrack.Read(pBuffer, dwChunkLength);//文件内容
if (0 != dwReadLength)
{
pHttpFile->Write(pBuffer, dwReadLength);//写入服务器本地文件,用二进制进行传送
}
}
fTrack.Close();
pHttpFile->Write((LPSTR)(LPCSTR)strPostFileData, strPostFileData.GetLength());
pHttpFile->EndRequest(HSR_SYNC);//此处异常*****************************此处异常
dwResponseLength = pHttpFile->GetLength();
while (0 != dwResponseLength)
{
szResponse = (LPSTR)malloc(dwResponseLength + 1);
szResponse[dwResponseLength] = '\0';
pHttpFile->Read(szResponse, dwResponseLength);
pThis->strResponse += szResponse;
free(szResponse);
dwResponseLength = pHttpFile->GetLength();
}
pHttpFile->Close();
delete pHttpFile;
DWORD dw ;
if (InternetQueryDataAvailable((HINTERNET)(*pHttpFile), &dw, 0, 0) && (dw == 0))
{
//设置成功标志
nSuccess = 0;
}
}
catch (CException* e)
{
TCHAR szCause[MAX_PATH] = {0};
e->GetErrorMessage(szCause, MAX_PATH);
e->Delete();
pThis->strError += szCause;
//删除http文件对象
if(pHttpFile != NULL ) delete pHttpFile;
//删除http连接对象
if(pHttpConnection != NULL) delete pHttpConnection;
//关闭http连接
Session.Close();
}
if (NULL != pBuffer)
{
free(pBuffer);
}
return nSuccess;