Solved

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

Posted on 2010-09-24
5
486 Views
Last Modified: 2012-06-27
Is there a function that does the opposite of URLDownloadToFile() ex. put a file to a URL in c++?
0
Comment
Question by:ken355
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 33754417
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
 

Author Comment

by:ken355
ID: 33754548
on the HTTPOpenRequest should i be using the PUT verb? instead of the POST?
0
 
LVL 86

Expert Comment

by:jkr
ID: 33754788
Files are usually transferred via POST - if your server accepts PUT, you can change that of course.
0
 

Author Comment

by:ken355
ID: 33756793
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
 

Author Closing Comment

by:ken355
ID: 33765300
Quick response
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I get Window Title of all opened process? 4 60
troubleshoot a python script 8 113
CSV file copy field 1 to field 2 2 62
Excel Web Add-in Where is Visual Basic used 9 80
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question