Click to See Complete Forum and Search --> : Send a File through HTTP


Sajid Khan
May 6th, 1999, 01:01 AM
Is it possible that i send a binary file of size approximately more than 64K through http protocol using MFC WinInet classes if yes then how?

Mahanthi
May 6th, 1999, 03:17 PM
Hi,
I have a few tips but not an exact solution to your problem.

If you are using FTP protocol and if you have write permissions you can write ( send ) a file onto the server easily. In case your situation is not FTP and instead it is HTTP then you have a problem as you need some component( could be activeX object, ISAPI Dll in case you are using IIS ) to reside on the server to do the handling of the contents of the file you will be sending over the internet. Even let us assume that you are ready to provide a component on the server side you still cannot ( well it becomes complex ) transfer files over the internet programatically as you will have a build a HTTP header and transmit the header to a webserver just the way IE or Netscape does. Microsoft has given some Internet Explorer SDK functions which if you use will do the job for you but that is where i will be stopping and you will have to do your own work.

Hope i can lead you in the right direction.

Mahanthi




mahanthi@rocketmail.com

August 19th, 1999, 10:29 AM
I started working today on WinInet for my new project and here is WinInet code but i am getting problem in how to create header. If you find any thing about it please le me know. You can use GET/POST in open request. GET is easier and works fine but i am still looking for POST.\

Mahesh

==============================



CInternetSession session;
CHttpConnection* pConnection = NULL;
CHttpFile* pFile1 = NULL;
char* buffer = new char[MAXBUF];
UINT nBytesRead = 0;
DWORD dwStatus;
CString g_strServerIP ;
CString g_strServerName = "localhost" ;
int g_nPort = 80 ;


// username/password doesn't work yet
if(!g_strServerName.IsEmpty()) {
pConnection = session.GetHttpConnection(g_strServerName,
(INTERNET_PORT) g_nPort);
}
else {
pConnection = session.GetHttpConnection(g_strServerIP,
(INTERNET_PORT) g_nPort);
}


CString strHeaders =
_T("Content-Type: application/x-www-form-urlencoded");
// URL-encoded form variables -
// name = "John Doe", userid = "hithere", other = "P&Q"
CString strFormData = _T("name=John+Doe&userid=hithere&other=P%26Q");


CHttpFile* pFile =
pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, "Readmedn.htm");
BOOL result = pFile->SendRequest(strHeaders,
(LPVOID)(LPCTSTR)strFormData, strFormData.GetLength());


if ( result)
AfxMessageBox("success");