// 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");}