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

ALong_Yue 2005-05-12 09:40:39
RT
...全文
421 点赞 收藏 17
写回复
17 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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 !!!!!!!!!!!
回复
相关推荐
发帖
网络编程
创建于2007-09-28

1.8w+

社区成员

VC/MFC 网络编程
申请成为版主
帖子事件
创建了帖子
2005-05-12 09:40
社区公告
暂无公告