打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
通过WinInet上传文件

通过WinInet上传文件

发表于2013/11/28 16:46:42  1034人阅读

分类: win网络编程

// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <Windows.h>#include <Windows.h>#include <WinINet.h>#include <stdio.h>#define BUFFSIZE 500BOOL UseHttpSendReqEx(TCHAR *upFile){	HINTERNET hSession=NULL, hConnect=NULL, hRequest=NULL;	hSession = InternetOpen(_T("test"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);	hConnect = InternetConnect(hSession,_T("192.168.2.192"), INTERNET_DEFAULT_HTTP_PORT, //hConnect = InternetConnect(hSession,_T("192.168.1.121"), INTERNET_DEFAULT_HTTP_PORT, 		NULL,NULL,INTERNET_SERVICE_HTTP,INTERNET_FLAG_NO_CACHE_WRITE,NULL);	INTERNET_BUFFERS BufferIn = {0};	DWORD dwBytesRead;	DWORD dwBytesWritten;	BYTE pBuffer[1024]; // Read from file in 1K chunks	BOOL bRead, bRet;	BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );		//hRequest = HttpOpenRequest (hConnect, "POST","/chess/webx/server/ool/header.php?&gameId=106&session=e5020849", NULL, NULL, NULL,  0, 0);	hRequest = HttpOpenRequest (hConnect, "POST","/texascilent_mb/tool/header.php?&gameId=106&session=e5020849", NULL, NULL, NULL,  0, 0);	if (!hRequest)	{		printf("Failed to open request handle: %lu\n", GetLastError ());		return FALSE;	}	HANDLE hFile = CreateFile (upFile, GENERIC_READ, FILE_SHARE_READ,		NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);	if (hFile == INVALID_HANDLE_VALUE)	{		printf("\nFailed to open local file %s.", upFile);		return FALSE;	}	BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);	printf ("File size is %d\n", BufferIn.dwBufferTotal );	if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, HSR_INITIATE, 0))	{		printf( "Error on HttpSendRequestEx %lu\n",GetLastError() );		return FALSE;	}	DWORD sum = 0;	do	{		if  (!(bRead = ReadFile (hFile, pBuffer, sizeof(pBuffer),			&dwBytesRead, NULL)))		{			printf ("\nReadFile failed on buffer %lu.",GetLastError());			break;		}		if (!(bRet=InternetWriteFile( hRequest, pBuffer, dwBytesRead,			&dwBytesWritten)))		{			printf ("\nInternetWriteFile failed %lu", GetLastError());			break;		}		sum += dwBytesWritten;	}	while (dwBytesRead == sizeof(pBuffer)) ;	CloseHandle (hFile);	printf ("Actual written bytes: %d\n", sum);	if(!HttpEndRequest(hRequest, NULL, 0, 0))	{		printf( "Error on HttpEndRequest %lu \n", GetLastError());		return FALSE;	}	Sleep(100000);	return TRUE;}void main( int argc, char **argv ){	UseHttpSendReqEx("C:\\Users\\Administrator\\Desktop\\test\\tt.jpg");}

0 0
暂无评论,我去发表~

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
模拟HTTP请求, POST方法(附源码+测试jsp代码) - Andy的日志 - 网易博...
C++读取网络url文件内容
开心网争车位外挂制作的编程思路(login, GET)
使用WinINet和WinHTTP实现Http访问
在EXE和DLL中,FindResource的区别
WinInet API 的异步方式使用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服