Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an http website using IIS according, It is successfully opening from web browsers from different PCs. Now what I am try to do is writing an normal text file in that server from different PC through below Code.

Now last InternetWriteFile is success, but nothing is written in that file??

Any one have any idea whats happening?
[INFO:wbsite http://10.195.13.128/PostData is opening through a default html site.

That PostData is in local disk D://PostData with Sample.txt file there.(its mapped through IIS)]

Actually may aim is to write a file in http server...(ftp not allowed in my project)

***************************************
C++
BOOL CPostFile::ConnectionEstablishment()
{
	BOOL bRet = TRUE;
	DWORD err;
	INTERNET_BUFFERS BufferIn = {0};

	hOpen_ = InternetOpen(L"PosrdataApp", INTERNET_OPEN_TYPE_PRECONFIG,
		NULL,
		NULL,
		/*INTERNET_FLAG_ASYNC*/0);
	if(NULL == hOpen_)
	{
		err = GetLastError();
		return FALSE;
	}
	
	hConnect_ = InternetConnect(hOpen_, L"10.195.13.128",
                INTERNET_DEFAULT_HTTP_PORT,
		NULL,		//Username
		NULL,		//Password
		INTERNET_SERVICE_HTTP,
		NULL,
		NULL);
	if(NULL == hConnect_)
	{
		err = GetLastError();
		return FALSE;
	}

	const TCHAR* lplpszAcceptTypes[] = {L"text/xml",
                L"application/xml",L"application/xhtml+xml",L"text/html;q=0.9",
                L"text/plain;q=0.8",L"image/png",L"*/*;q=0.5", NULL};
								
	hRequest_ = HttpOpenRequest(hConnect_, L"POST", L"PostData/Sample.txt",
		NULL, NULL, lplpszAcceptTypes, INTERNET_FLAG_KEEP_CONNECTION, 0);
	if(NULL == hRequest_)
	{
		err = GetLastError();
		return FALSE;
	}

	if(!HttpAddRequestHeaders(hRequest_,
		L"Content-Type: text/plain",
		-1L,
		HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD))
	{
		err = GetLastError();
		return FALSE;
	}

	ZeroMemory(&BufferIn, sizeof(INTERNET_BUFFERS)); 
	//BufferIn.dwBufferTotal = sizeof(fpFileToBeWritten_);

	//fseek(fpFileToBeWritten_,0,SEEK_END);
	//long  size=ftell (fpFileToBeWritten_);
	BufferIn.dwBufferTotal =8;

	
	BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS);

	if(!HttpSendRequestEx(hRequest_, &BufferIn, NULL, HSR_INITIATE, 0))	
	{
		err = GetLastError();
		//return FALSE;
	}

	//char smallBuff[1024]= {0};
	//DWORD dwBytesWritten=0;
	//size_t res = fread(smallBuff,1,500,fpFileToBeWritten_);

	InternetWriteFile( hRequest_, /*smallBuff*/"hi sala", 8,&dwBytesWritten);
	err = GetLastError();
	return bRet;
}
*********************

Can Anyone help?
Posted
Updated 30-Nov-12 2:31am
v2

First of all you have to call InternetCloseHandle at the end. Maybe this is not enough, but you must call it
 
Share this answer
 
Hey, did you got any solution...even i'm having the same issue :(
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900