現在專案需要通過http上傳檔案,要用C++寫,使用的是CHttpFile類,下載沒有問題,但上傳不知道怎么寫,具體要求如下
uj5u.com熱心網友回復:
自己頂頂,在線等,比較著急,謝各位大神
uj5u.com熱心網友回復:

參考
CString strHttpName="http://localhost/TestReg/RegForm.aspx"; // 需要提交資料的頁面
CString strFormData = "username=abc&password=123"; // 需要提交的資料
CInternetSession sess;
CHttpFile* fileGet;
CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded"); // 請求頭
try
{
fileGet=(CHttpFile*)sess.OpenURL(strHttpName);//打開檔案
}
catch(CException* e)
{
fileGet = 0;
throw;
}
CString strSentence, strGetSentence = "";
if(fileGet)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = fileGet->QueryInfo(HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 &&dwStatus<300 )
{
BOOL result = fileGet->SendRequest(strHeaders, (LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());
while(fileGet->ReadString(strSentence)) // 讀取提交資料后的回傳結果
{
strGetSentence = strGetSentence + strSentence + char(13) + char(10);
}
AfxMessageBox(strGetSentence); // 顯示回傳網頁內容
}
else
{
strSentence.Format("POST出錯,錯誤碼:%d", dwStatus);
AfxMessageBox(strSentence);
}
fileGet->Close();
delete fileGet;
}
else
AfxMessageBox("不能找到網頁檔案!");
sess.Close();
uj5u.com熱心網友回復:
http://blog.csdn.net/love3s/article/details/7936315
uj5u.com熱心網友回復:
謝謝了,我先試試,如果成功就太謝謝您了
uj5u.com熱心網友回復: