C++ http上传文件问题 求教,在线等,谢各位高手

handaokong 2018-01-20 06:32:08
现在项目需要通过http上传文件,要用C++写,使用的是CHttpFile类,下载没有问题,但上传不知道怎么写,具体要求如下
...全文
850 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
纵使微芒如烟 2019-12-10
  • 打赏
  • 举报
回复
引用 8 楼 纵使微芒如烟 的回复:
感觉go来实现更简单
毕竟有强大的内裤
纵使微芒如烟 2019-12-10
  • 打赏
  • 举报
回复
感觉go来实现更简单
handaokong 2018-01-21
  • 打赏
  • 举报
回复
引用 3 楼 zgl7903 的回复:
http://blog.csdn.net/love3s/article/details/7936315
HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); 这些是自己定义的类型?
handaokong 2018-01-21
  • 打赏
  • 举报
回复
引用 2 楼 smwhotjay 的回复:
参考
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();
谢谢了,我先试试,如果成功就太谢谢您了
handaokong 2018-01-21
  • 打赏
  • 举报
回复
[quote=引用 2 楼 smwhotjay 的回复:] 参考
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();[/quote 不好意思,这个post我知道,但我需求是上传文件,第三个参数是 file 类,这个我不知道怎么传
smwhotjay 2018-01-20
  • 打赏
  • 举报
回复
参考
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();
handaokong 2018-01-20
  • 打赏
  • 举报
回复
自己顶顶,在线等,比较着急,谢各位大神

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧