Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3672236
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:35:03+00:00 2026-05-19T02:35:03+00:00

I am posting the file to server and its working fine, But the my

  • 0

I am posting the file to server and its working fine, But the my code fails when i try to post the .zip file. May be my code is wrong in the reading the zip file contents data.

ifstream::pos_type size;
char * memblock;
ifstream file ("example.zip", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
 size = file.tellg();
 memblock = new char [size];
 file.seekg (0, ios::beg);
 file.read (memblock, size);
 file.close();

 postBody.AppendFormat("Content-Disposition: form-data; name=\"datafile\"; filename=\"%s\"; \r\n\n%s", zipFilePath, memblock); 
 postBody.AppendFormat("\r\n--%s--\r\n", boundary);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:35:04+00:00Added an answer on May 19, 2026 at 2:35 am

    Finally i got the answer for this question:

     CString boundary = "-------------------------------7d8b32060180";
              CString postBody(_T(""));
              postBody.AppendFormat("\r\n--%s\r\n", boundary);
    
              postBody.AppendFormat("Content-Disposition: form-data; name=\"name\"\n\n%s", name);
              postBody.AppendFormat("\n--%s\r\n", boundary);
    
              postBody.AppendFormat("Content-Disposition: form-data; name=\"email\"\n\n\n\r\r\n%s\n", emailID);
              postBody.AppendFormat("\r\n--%s\r\n", boundary);
    
              postBody.AppendFormat("Content-Disposition: form-data; name=\"comments\"\n\n\r\r\n%s\n", comment);
              postBody.AppendFormat("\r\n--%s\r\n", boundary);
    
              postBody.AppendFormat("Content-Disposition: form-data; name=\"subject\"\n\n\r\r\n%s\n", subjectLine);  
              postBody.AppendFormat("\r\n--%s\r\n", boundary);
    
              int  httpReqBodyLen    = 0;
              BYTE* httpRequestBody  = NULL;              
              TCHAR* fileBuff        = NULL;
              int fileBufLen         = 0; 
              if (!filePath.IsEmpty())
              {                       
                    CFile vidFile; 
                    if (vidFile.Open(filePath, CFile::modeRead))             
                    {
                          fileBufLen = vidFile.GetLength();
                          fileBuff = new TCHAR[fileBufLen + 1];
                          vidFile.Read(fileBuff, fileBufLen);
                          fileBuff[fileBufLen] = '\0';
                          vidFile.Close();
                          postBody.AppendFormat("Content-Disposition: form-data; name=\"datafile\"; filename=\"%s\"; \r\n\n", filePath);  
                    }     
              }
    
              httpReqBodyLen = postBody.GetLength() + strlen("\n--" + boundary + "--\r\n") + fileBufLen + 1;
              httpRequestBody = new BYTE[httpReqBodyLen];  //create enough buffer memory
              memset(httpRequestBody, 0x00, httpReqBodyLen);
              memcpy(httpRequestBody, postBody.GetString(), postBody.GetLength()); //write header to final buffer
              if (!filePath.IsEmpty() && fileBuff)
              {
                    memcpy(httpRequestBody + postBody.GetLength(), fileBuff, fileBufLen); //add file contents
                    delete fileBuff;
              }
    
              memcpy(httpRequestBody + postBody.GetLength() + fileBufLen, _T("\n--" + boundary + "--\r\n"), strlen("\n--" +boundary+ "--\r\n")); 
              httpRequestBody[httpReqBodyLen - 1] = '\0';
    
              CString strHeaderCS;
              strHeaderCS.AppendFormat("Content-Type:multipart/form-data; boundary=%s\r\n", boundary);
              strHeaderCS.AppendFormat("Accept-Charset:ISO-8859-15, utf-8;q=0.66, *;q=0.66\r\n");
              strHeaderCS.AppendFormat("Keep-Alive:5000\r\n");
              strHeaderCS.AppendFormat("Accept-Language:en\r\n");
              strHeaderCS.AppendFormat("Accept-Encoding:gzip, deflate\r\n");
              strHeaderCS.AppendFormat("User-Agent:Mozilla/4.0 (Windows; U; Windows Vista;)\r\n");
              strHeaderCS.AppendFormat("Accept:text/xml,application/xml,application/xhtml+xml, application/vid,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n");
              strHeaderCS.AppendFormat("Content-Length:%d\r\n", httpReqBodyLen);
    
              strHeaderCS.AppendFormat("Connection:keep-alive\r\n");
              strHeaderCS.AppendFormat("Host:www.filemagic.org\r\n");
    
              CString strObject, server;
              INTERNET_PORT port;
              DWORD dwServiceType;
              USES_CONVERSION;
              AfxParseURL(strURL, dwServiceType, server, strObject, port);
              HINTERNET hINetOpen, hINetConnect, hINetRequest;
              try
              {
                    hINetOpen = InternetOpen(_T("SplashID"),  INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);//AK
                    if (hINetOpen != NULL){
                          hINetConnect = InternetConnect(hINetOpen, server, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_IDN_PROXY, 0); 
                          if (hINetConnect != NULL){
                                hINetRequest = HttpOpenRequest(hINetConnect, _T("POST"), strObject, HTTP_VERSION, 0, NULL,  INTERNET_FLAG_RELOAD |INTERNET_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE, 0);
                                if (hINetRequest != NULL){
                                      if(HttpSendRequest(hINetRequest, strHeaderCS, strHeaderCS.GetLength(), (LPVOID) httpRequestBody, httpReqBodyLen)) {
                                            CString sBodyText;
                                            DWORD nRead= 1024;
                                            char szBuf[ 1025 ] = {0};
                                            while ( nRead > 0 ) {
                                                  // Read in a temporary buffer
                                                  InternetReadFile(hINetRequest, szBuf, 1024, &nRead);
                                                  szBuf[nRead] = '\0';
                                                  sBodyText += szBuf;
                                            }
                                      }                                   
                                }
                          }
                    }
              }
              catch(...)
              {
              }
              if (threadData)
              {
                  delete threadData;
                  threadData = NULL;
              }
              if (httpRequestBody)
              {
                  delete httpRequestBody;
                  httpRequestBody = NULL;
              }
              if(hINetOpen)
              {
                  InternetCloseHandle(hINetOpen);
                  hINetOpen = NULL;
              }
              if (hINetConnect)
              {
                  InternetCloseHandle(hINetConnect);
                  hINetConnect = NULL;
              }
              if (hINetRequest)
              {
                  InternetCloseHandle(hINetRequest);
                  hINetRequest = NULL;
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code to perform some simultaneous HTTP posting and file
I'm currently working on posting a file from a C# application to an image
I have a jabber client that is reading from its stdin and posting PubSub
I am posting an XML file to a server using curl. Everthing works perfectly
I'm posting a file in Javascript using the new FormData interface. When I send
I am taking a text file from user and then posting that file back
I am posting a load of information to this file, and then trying to
I have a problem posting file via ajax jQuery function. I have something like
Precision loss is one thing, but precision gain??? I have a text file w/
I am posting JSON data to an ASP.NET MVC2 server. I am posting large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.