soket用http协议自己写命令可以从http服务器下载文件,那上传怎么做 soket用http协议自己写命令可以从http服务器下载文件,上传怎么做,需要自己写服务器端么?服务器能象下载一样自动接受上传命令来接收,还是要自己写服务器来同讯? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HTTP上传与下载一样,只不过把数据放到POST数据中 下载指令是,get,上传应该是是put了 那能断点续传么,用put命令,需要自己在服务器上启动什么服务么 #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 500void 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;} http://community.csdn.net/Expert/topic/3522/3522947.xml?temp=.9867212 不想用wininet写,想直接自己用socket,用InternetWriteFile我试传一个84m的文件就传不动了,又不能显示传送进度,有没有 自己写socket传送的还有,跟http服务器传文件,不自己写接收端的话,要文件传送了一半失败了,服务器就会清除该文件的,不能做断点续传的是不是。 1.www.codeproject.com/internet/ httpget-post.asp?msg=294637 2.need webserver support it. kingzai(stevenzhu) www.codeproject.com/internet/ httpget-post.asp?msg=294637 这个下不下来,下来一个asp网页,你有代码么能发给我么 这个好像跟我说的有点区别把,用不上need webserver support it.怎么设置服务器?? 这个好像跟我说的有点区别把,用不上need webserver support it.怎么设置服务器?? 服务不自动运行??? 小弟初接触mysql,我通过VC访问ADO访问,里面的关系不清楚,mysql数据 的内容我想存在WINDOWS下,用那些软件把他们连起来 FORMVIEW和Dialog 数据库操作效率问题 当程序以system权限运行的时候,如何得到当前登陆的本地用户名?getusername好像只能得到运行本程序的用户名。 [求助]winsock XLEzAutomation和CSpreadSheet打开excel速度对比 谁能给我找个进程通信的例子? 一个初学者有关显示的问题. COM 如何在线程里使用 为什么我的线程退出码是 3 (0x03)????????? 数据库的几个问题
#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 500void 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;
}
还有,跟http服务器传文件,不自己写接收端的话,要文件传送了一半失败了,服务器就会清除该文件的,不能做断点续传的是不是。
2.need webserver support it.
www.codeproject.com/internet/ httpget-post.asp?msg=294637
这个下不下来,下来一个asp网页,你有代码么能发给我么
怎么设置服务器??
怎么设置服务器??