通过HTTP的POST方式,如何上传文件到服务器?

ALong_Yue 2005-05-12 09:40:39
RT
...全文
743 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
kyh1234567 2005-05-20
  • 打赏
  • 举报
回复
kugou123(酷狗):
正解,我刚刚试过,把#include <process.h>加上后就没问题了
kugou123 2005-05-20
  • 打赏
  • 举报
回复
#include <process.h> 试试
ALong_Yue 2005-05-20
  • 打赏
  • 举报
回复
DING
ALong_Yue 2005-05-16
  • 打赏
  • 举报
回复
kugou123(酷狗):编译你在blog提供的代码,出现下列问题:

nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
kugou123 2005-05-13
  • 打赏
  • 举报
回复
我的BLOG收录了一篇文章。看上面的链接。。
kugou123 2005-05-13
  • 打赏
  • 举报
回复
利用HTTP方式上传

http://www.xiaozhou.net/cooldog/blogview.asp?logID=57
ALong_Yue 2005-05-13
  • 打赏
  • 举报
回复
UP Again
Kudeet 2005-05-12
  • 打赏
  • 举报
回复
Q177188 Using HttpSendRequestEx for Large POST Requests
ALong_Yue 2005-05-12
  • 打赏
  • 举报
回复
最好使用MFC类实现:(
ALong_Yue 2005-05-12
  • 打赏
  • 举报
回复
谢谢大家的回复!!!

vcmute(横秋):可以给一个例子吗?

xuzheng318(forever C++)(忧郁王子):我需要上传文件,而不是POST一个http请求这么简单。

在服务器端,有一个页面负责接收。请高手多多帮忙!!
ALong_Yue 2005-05-12
  • 打赏
  • 举报
回复
up!!
xuzheng318 2005-05-12
  • 打赏
  • 举报
回复
void CProject1Dlg::OnOK(void)
{
CString m_sServer;
CString m_sPath;
UpdateData(true);
if(m_sUrl.IsEmpty())
return;
CString stmp;
stmp=m_sUrl;
//m_sUrl is a edit box to input URL;
//you can use http://www.csdn.net/expert/topic/55011.shtm or
//http://www.aaa.com/test.asp?id=xxx
stmp.MakeUpper();
if(stmp.Left(7)!="HTTP://")
{
AfxMessageBox("wrong url header");
return ;
}
else
stmp=m_sUrl.Mid(7);
int nSlashPos=stmp.Find("/");
if(nSlashPos!=-1)
{
m_sServer=stmp.Left(nSlashPos);
m_sPath=stmp.Mid(nSlashPos);
stmp= m_sServer+" \n"+m_sPath;
AfxMessageBox(stmp);
}
else
{
AfxMessageBox("/ not find");
return;
}
HINTERNET hSession=::InternetOpen("raw html reader",PRE_CONFIG_INTERNET_ACCESS,"",INTERNET_INVALID_PORT_NUMBER,0);
if(hSession==NULL)
{
AfxMessageBox("Internetopen failed");
return;
}
HINTERNET hConnect=::InternetConnect(hSession,m_sServer,INTERNET_INVALID_PORT_NUMBER,"","",INTERNET_SERVICE_HTTP,0,0);
if(hConnect==NULL)
{
AfxMessageBox("InternetConnect failed");
::InternetCloseHandle(hSession);
return;
}
HINTERNET hHttpFile=::HttpOpenRequest(hConnect,"GET",m_sPath,HTTP_VERSION,NULL,0,INTERNET_FLAG_DONT_CACHE,0);
if(hHttpFile==NULL)
{
AfxMessageBox("can not call HttpOpenRequest");
::InternetCloseHandle(hConnect);
::InternetCloseHandle(hSession);
return;
}
CWaitCursor wait;
BOOL bSend=::HttpSendRequest(hHttpFile,NULL,0,0,0);
if(bSend)
{
char cQueryBuf[16];
DWORD dwFileSize;
DWORD dwQueryBufLen=sizeof(cQueryBuf);
BOOL bQuery=::HttpQueryInfo(hHttpFile,HTTP_QUERY_CONTENT_LENGTH,cQueryBuf,&dwQueryBufLen,NULL);
if(bQuery)
{
dwFileSize=(DWORD)atol(cQueryBuf);
}
else
dwFileSize=10*1024;
char *lpszBuf=new char[dwFileSize+1];
DWORD dwBytesRead;
BOOL bRead=::InternetReadFile(hHttpFile,lpszBuf,dwFileSize+1,&dwBytesRead);
m_sContent=(LPCTSTR)lpszBuf;
delete lpszBuf;
}
UpdateData(false);

}
qrlvls 2005-05-12
  • 打赏
  • 举报
回复
http://search.csdn.net/Expert/topic/1084/1084909.xml?temp=.3063318
vcmute 2005-05-12
  • 打赏
  • 举报
回复
post数据,boundary随即生成

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="user"

Wilson Peng
--AaB03x
content-disposition: form-data; name="myfile"
Content-type: multipart/mixed, boundary=BbC04y

--BbC04y
Content-disposition: attachment; filename="myphoto.gif"
Content-type: image/gif
Content-Transfer-Encoding: binary

...myphoto.gif 内容略...
--BbC04y--
--AaB03x--
beipiao 2005-05-12
  • 打赏
  • 举报
回复
其实这种问题的解答,论坛里面搜索一下,有很多的
beipiao 2005-05-12
  • 打赏
  • 举报
回复
rfc1867,有关http form的详细说明
接收到的数据,注意要判断是否为chunk编码
ALong_Yue 2005-05-12
  • 打赏
  • 举报
回复
Ding A !!!!!!!!!!!

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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