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

From: Henchman:crg (colin_at_colingirling.my-bulldog.com)
Date: 12/22/04


Date: Wed, 22 Dec 2004 18:48:25 -0000

What do I need to parse within the binary data?
Also, I am sending form data with the binary file, should I send that using
a seperate SendRequest?

"Random User" <qvnmfddujfu@mailinator.com> wrote in message
news:OcRS$BD6EHA.1300@TK2MSFTNGP14.phx.gbl...
> 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" <colin@colingirling.my-bulldog.com> wrote in message
> news:LNadnZMfI_aH41XcRVnyuA@giganews.com...
>> 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 = "www.myserver.com";
>> CInternetSession *pInetSession = new CInternetSession(strHttpSite, 1,
>> INTERNET_INVALID_PORT_NUMBER);
>>
>> DWORD dwServiceType;
>> CString strServerName;
>> CString strObject;
>> INTERNET_PORT nPort;
>> AfxParseURL(strHttpSite, dwServiceType, strServerName, strObject, nPort)
>>
>> CHttpConnection *pHttpConnection =
>> pInetSession->GetHttpConnection(strServerName);
>>
>> CHttpFile *pHttpFile =
>> pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
> "upload.asp",
>> NULL, 1, NULL, NULL,
>>
> INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE
> );
>>
>> 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.
>
>