Re: Anyone know how to use CHttpFile to upload a file to a server?

From: Random User (
Date: 12/22/04

Date: Wed, 22 Dec 2004 09:14:00 -0500

Unless your strFormData is properly formatted, it's meant to fail. You can
either format it the same way as GET parameters
(formdata=h%20e%20l%20l%20o), which is very easy to get in ASP, or as
multipart form data, which needs to be manually parsed in ASP.

For transmitting binary files we found the latter more suitable. Proper
formatting for multipart form data is sort of a mess, but you can sniff what
IE sends and/or read formal description.

But the rest of the code looks ok [if compiled].

"Henchman:crg" <> wrote in message
> Got some sample code here, just not sure what else I need to do.
> Trying to post a asp page and get a binary file transmitted to the server.
> CString strHttpSite = "";
> CInternetSession *pInetSession = new CInternetSession(strHttpSite, 1,
> DWORD dwServiceType;
> CString strServerName;
> CString strObject;
> AfxParseURL(strHttpSite, dwServiceType, strServerName, strObject, nPort)
> CHttpConnection *pHttpConnection =
> pInetSession->GetHttpConnection(strServerName);
> CHttpFile *pHttpFile =
> pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
> DWORD dwStatusCode = 0;
> if( pHttpFile->SendRequest() ) //strHeaders,
> const_cast<char*>(static_cast<const char*>(strFormData)),
> strFormData.GetLength()) )
> pHttpFile->QueryInfoStatusCode(dwStatusCode);
P.S. This code is not going to compile.