Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ IIS
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)
 
***************************************
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 30-Nov-12 3:08am
Edited 30-Nov-12 3:31am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all you have to call InternetCloseHandle at the end. Maybe this is not enough, but you must call it
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hey, did you got any solution...even i'm having the same issue :(
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100