Is there a function that does the opposite of URLDownloadToFile() ex. put a file to a URL in c++?

Is there a function that does the opposite of URLDownloadToFile() ex. put a file to a URL in c++?
ken355Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jkrConnect With a Mentor Commented:
Unfortunately no, since things are more complex here. Ther are a few things to consider: If the file is binary, you need to base64 encode it (see http://www.codeproject.com/KB/cpp/base64coding.aspx - "Base64 Encoding and Decoding"). Then, you can send the file as outlined in the sample code at http://support.microsoft.com/kb/165298 ("How to simulate a Form POST request by using WinInet") with some changes:
   static TCHAR hdrs[] =
      _T("Content-Type: multipart/mixed");
   static TCHAR data[] = /* contains encoded file */;
  static LPSTR accept[2]={"*/*", NULL};

   // for clarity, error-checking has been removed
   HINTERNET hSession = InternetOpen("MyAgent",
      INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
   HINTERNET hConnect = InternetConnect(hSession, _T("ServerNameHere"),
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
   HINTERNET hRequest = HttpOpenRequest(hConnect, "POST",
      _T("FormActionHere"), NULL, NULL, accept, 0, 1);
   HttpSendRequest(hRequest, hdrs, strlen(hdrs), data, strlen(data));
   // close any valid internet-handles

Open in new window

0
 
ken355Author Commented:
on the HTTPOpenRequest should i be using the PUT verb? instead of the POST?
0
 
jkrCommented:
Files are usually transferred via POST - if your server accepts PUT, you can change that of course.
0
 
ken355Author Commented:
thank you i understand what is going on, last question is regarding HttpOpenRequest(hConnect, "POST",
      _T("FormActionHere"), NULL, NULL, accept, 0, 1);

The lpszObjectName parameter ex. "FormActionHere" (the name of the target object of the verb) should this be the filename that i am sending?
0
 
ken355Author Commented:
Quick response
0
All Courses

From novice to tech pro — start learning today.