CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

soket用http协议自己写命令可以从http服务器下载文件,那上传怎么做

楼主constants(constants)2004-12-03 16:57:46 在 VC/MFC / 基础类 提问

soket用http协议自己写命令可以从http服务器下载文件,上传怎么做,需要自己写服务器端么?服务器能象下载一样自动接受上传命令来接收,还是要自己写服务器来同讯? 问题点数:0、回复次数:17Top

1 楼constants(constants)回复于 2004-12-05 15:58:14 得分 0

没人回答么Top

2 楼Semigod()回复于 2004-12-05 16:34:49 得分 0

HTTP上传与下载一样,只不过把数据放到POST数据中Top

3 楼pleasehelpme(革命尚未成功,同志仍需努力)回复于 2004-12-05 16:39:02 得分 0

帮顶Top

4 楼flinming(flinming)回复于 2004-12-05 17:28:47 得分 0

下载指令是,get,上传应该是是put了  
  Top

5 楼Trashy(【叶落随风】)回复于 2004-12-05 22:20:07 得分 0

学习一下~Top

6 楼constants(constants)回复于 2004-12-08 09:20:46 得分 0

那能断点续传么,用put命令,需要自己在服务器上启动什么服务么Top

7 楼kingzai(stevenzhu)回复于 2004-12-08 09:44:46 得分 0

#include   <afxdtctl.h>  
  #include   <Windows.h>  
  #include   <WinINet.h>  
  #include   <stdio.h>  
  BOOL   UseHttpSendReqEx(HINTERNET   hRequest,   DWORD   dwPostSize,CString   strLocalFile);  
  BOOL   Upload(CString   bstrLocalFile,CString   bstrServerIP,CString   strServerPort,CString   bstrRemoteFile);  
  #define   BUFFSIZE   500  
   
  void   main(   int   argc,   char   **argv   )  
  {  
   
  if   (argc   <   5)  
  {  
  printf("Usage:   Bigpost   <LocalFile>   <ServerIP><ServerPort><ReomteFile>\n");  
  printf("<LocalFile>   is   the   local   file   to   POST\n");  
  printf("<ServerIP>   is   the   server's   IP   to   POST   to\n");  
  printf("<ServerPort>   is   the   server's   Port   to   POST   to\n");  
  printf("<ReomteFile>   is   the   virtual   path   to   POST   to\n");  
  exit(0);  
  }  
  Upload(argv[1],argv[2],argv[3],argv[4]);  
  }  
  BOOL   UseHttpSendReqEx(HINTERNET   hRequest,   DWORD   dwPostSize,CString   strLocalFile)  
  {  
  DWORD   dwRead;  
  BYTE*   buffer;  
  printf("Local   file:%s\n",strLocalFile);  
  FILE*   fLocal;  
  if((fLocal=fopen(strLocalFile,"rb"))==NULL){  
  printf("Can't   open   the   file:%s,maybe   it   doesn't   exist!\n",strLocalFile);  
  return   false;  
  }  
  fseek(fLocal,0L,SEEK_END);  
  dwRead=ftell(fLocal);  
  rewind(fLocal);  
  buffer=(BYTE   *)malloc(dwRead);  
  if(!buffer){  
  printf("not   enough   memory!\n");  
  return   false;  
  }  
  printf("length   of   file:%d\n",dwRead);  
  dwRead=fread(buffer,1,dwRead,fLocal);  
  dwPostSize=dwRead;  
   
  INTERNET_BUFFERS   BufferIn;  
  DWORD   dwBytesWritten;  
  BOOL   bRet;  
  BufferIn.dwStructSize   =   sizeof(   INTERNET_BUFFERS   );   //   Must   be   set   or   error   will   occur  
          BufferIn.Next   =   NULL;    
          BufferIn.lpcszHeader   =   NULL;  
          BufferIn.dwHeadersLength   =   0;  
          BufferIn.dwHeadersTotal   =   0;  
          BufferIn.lpvBuffer   =   NULL;                                  
          BufferIn.dwBufferLength   =   0;  
          BufferIn.dwBufferTotal   =   dwPostSize;   //   This   is   the   only   member   used   other   than   dwStructSize  
          BufferIn.dwOffsetLow   =   0;  
          BufferIn.dwOffsetHigh   =   0;  
   
          if(!HttpSendRequestEx(   hRequest,   &BufferIn,   NULL,   0,   0))  
          {  
                  printf(   "Error   on   HttpSendRequestEx   %d\n",GetLastError()   );  
                  return   FALSE;  
          }  
  bRet=TRUE;  
  if(bRet=InternetWriteFile(   hRequest,   buffer,   dwPostSize,   &dwBytesWritten))  
  printf(   "\r%d   bytes   sent.",   dwPostSize);  
  if(!bRet)  
  {  
                  printf(   "\nError   on   InternetWriteFile   %lu\n",GetLastError()   );  
                  return   FALSE;  
          }  
   
          if(!HttpEndRequest(hRequest,   NULL,   0,   0))  
          {  
                  printf(   "Error   on   HttpEndRequest   %lu   \n",   GetLastError());  
                  return   FALSE;  
          }  
  fclose(fLocal);  
  free(buffer);  
  return   TRUE;  
  }  
   
  BOOL   Upload(CString   strLocalFile,CString   strServerIP,CString   strServerPort,CString   strRemoteFile){  
  DWORD   dwPostSize=0;  
  int   intServerPort=atoi(strServerPort);  
  HINTERNET   hSession   =   InternetOpen(   "HttpSendRequestEx",   INTERNET_OPEN_TYPE_PRECONFIG,  
  NULL,   NULL,   0);  
  if(!hSession)  
  {  
  printf("Failed   to   open   session\n");  
  return   FALSE;  
  }  
  HINTERNET   hConnect   =   InternetConnect(hSession,   strServerIP,   intServerPort,  
  NULL,   NULL,   INTERNET_SERVICE_HTTP,NULL,   NULL);  
  if   (!hConnect){  
  printf(   "Failed   to   connect\n"   );  
  return   FALSE;  
  }else{  
  HINTERNET   hRequest   =   HttpOpenRequest(hConnect,   "PUT",   strRemoteFile,    
  NULL,   NULL,   NULL,   INTERNET_FLAG_NO_CACHE_WRITE,   0);  
  if   (!hRequest){  
  printf(   "Failed   to   open   request   handle\n"   );  
  }else{  
  if(UseHttpSendReqEx(hRequest,   dwPostSize,strLocalFile))  
  {  
  char   pcBuffer[BUFFSIZE];  
  DWORD   dwBytesRead;  
   
  printf("\nThe   following   was   returned   by   the   server:\n");  
  do  
  { dwBytesRead=0;  
  if(InternetReadFile(hRequest,   pcBuffer,   BUFFSIZE-1,   &dwBytesRead))  
  {  
  pcBuffer[dwBytesRead]=0x00;   //   Null-terminate   buffer  
  printf("%s",   pcBuffer);  
  }  
  else  
  printf("\nInternetReadFile   failed");  
  }while(dwBytesRead>0);  
  printf("\n");  
  }  
  if   (!InternetCloseHandle(hRequest))  
  printf(   "Failed   to   close   Request   handle\n"   );  
  }  
  if(!InternetCloseHandle(hConnect))  
  printf("Failed   to   close   Connect   handle\n");  
  }  
  if(   InternetCloseHandle(   hSession   )   ==   FALSE   ){  
  printf(   "Failed   to   close   Session   handle\n"   );  
  return   FALSE;  
  }  
  printf(   "\nFinished.\n"   );  
  return   TRUE;  
  }Top

8 楼tigerjacky(林石--抢滩VC)回复于 2004-12-08 09:48:09 得分 0

gzTop

9 楼constants(constants)回复于 2004-12-08 10:47:24 得分 0

不用自己在服务器上写程序,直接系统就能接收上传的文件是么。要中途断了能续传么Top

10 楼kingzai(stevenzhu)回复于 2004-12-08 14:12:34 得分 0

http://community.csdn.net/Expert/topic/3522/3522947.xml?temp=.9867212Top

11 楼hjunxu(hjun)回复于 2004-12-08 14:28:56 得分 0

顶。Top

12 楼chuanke((C ) 2005【空间代数】. All rights reserved .)回复于 2004-12-08 15:44:47 得分 0

gzTop

13 楼constants(constants)回复于 2004-12-27 09:31:02 得分 0

不想用wininet写,想直接自己用socket,用InternetWriteFile我试传一个84m的文件就传不动了,又不能显示传送进度,有没有   自己写socket传送的  
  还有,跟http服务器传文件,不自己写接收端的话,要文件传送了一半失败了,服务器就会清除该文件的,不能做断点续传的是不是。Top

14 楼kingzai(stevenzhu)回复于 2004-12-27 10:26:05 得分 0

1.www.codeproject.com/internet/   httpget-post.asp?msg=294637    
  2.need   webserver   support   it.Top

15 楼constants(constants)回复于 2004-12-27 14:10:02 得分 0

kingzai(stevenzhu)    
  www.codeproject.com/internet/   httpget-post.asp?msg=294637    
  这个下不下来,下来一个asp网页,你有代码么能发给我么Top

16 楼constants(constants)回复于 2004-12-27 14:44:56 得分 0

这个好像跟我说的有点区别把,用不上  
   
  need   webserver   support   it.  
  怎么设置服务器??Top

17 楼constants(constants)回复于 2004-12-27 14:45:22 得分 0

这个好像跟我说的有点区别把,用不上  
   
  need   webserver   support   it.  
  怎么设置服务器??Top

相关问题

  • 关于HTTP服务器
  • 请问Web服务器与HTTP服务器有什么区别?
  • 如何调用FTP命令来管理FTP服务器???
  • 查看SQL 服务器运行速度用什么命令???
  • 编程高手&CS高手:CS 服务器命令谁有?
  • 对方的服务器 AT 命令没有启运怎么办????
  • 急:谁有Domino服务器命令详解啊?
  • oracle9i中装库命令,oracle服务器配置--求救!
  • 获取服务器时间的ORA内部命令是什么
  • 如何用net命令连接工作组中的服务器?

关键词

  • 服务器
  • 下载
  • null
  • flocal
  • bufferin
  • dwread
  • strlocalfile
  • 命令
  • dwpostsize
  • cstring

得分解答快速导航

  • 帖主:constants

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo