Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Following code unable to write/upload file on a HTTP Server

Following code unable to write/upload file on a HTTP Server

Scheduled Pinned Locked Moved C / C++ / MFC
c++phpcomsysadminxml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dhiraj kumar Saini
    wrote on last edited by
    #1

    My following code is unable to upload/write file on the server. Please tell me whats wrong or how can i upload it in a different way on an HTTP Server. I am using MFC.

    INTERNET_BUFFERS BufferIn = {0};
    DWORD dwBytesRead;
    DWORD dwBytesWritten;
    BYTE pBuffer[1024]; // Read from file in 1K chunks
    BOOL bRead, bRet;
    HANDLE hFile;

    HINTERNET hSession = InternetOpen(NULL,
                                      INTERNET\_OPEN\_TYPE\_PRECONFIG,
                                      NULL,
                                      NULL,
                                      0);
    HINTERNET hConnection = InternetConnect(hSession, 
                                            \_T("www.crmpanel.com"),  // Server
                                            INTERNET\_DEFAULT\_HTTP\_PORT,
                                            NULL,     // Username
                                            NULL,     // Password
                                            INTERNET\_SERVICE\_HTTP,
                                            0,        // Synchronous
                                            NULL);    // No Context
    
    
    
    
     BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS );
    
     HINTERNET hRequest = HttpOpenRequest(hConnection,
    										\_T("PUT"),
    										\_T("cp3/wn\_fupload-oo.php"),
    										NULL,
    										NULL,
    										NULL,
    										0,
    										0);
     if (!hRequest)
     {
       //printf("Failed to open request handle: %lu\\n", GetLastError ());
    	 MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK);
       return ;
     }
    
    //HttpAddRequestHeaders(hRequest, \_T("Content-Type: multipart/form-data;sid=52501;"), -1, HTTP\_ADDREQ\_FLAG\_ADD);
    
    
    
    
     hFile = CreateFile (\_T("c:\\\\Image1.gif"),
    					GENERIC\_READ,
    					FILE\_SHARE\_READ,
    					NULL,
    					OPEN\_EXISTING,
    					FILE\_ATTRIBUTE\_NORMAL,
    					NULL);
    
     if (hFile == INVALID\_HANDLE\_VALUE)
     {
       //printf("\\nFailed to open local file.");
        MessageBox(\_T("Failed to open local file"),NULL,MB\_OK);
       return ;
     }
    
    
    
     BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
     MessageBox(\_T("File size is"),NULL,MB\_OK);
     //printf ("File size is %d\\n");//, BufferIn.dwBufferTotal );
    
    // CString h = \_T("Content-Type: multipart/form-data");
    
    //CString s = \_T("filename=Iamge1.xml&filetype=gif&filesize=70204&sid=52501&csesid=111");
    
    //BOOL bo = HttpSendRequest(hRequest,(LPCTSTR)&h, h.GetLength(),(LPVOID)&s ,s.GetLength());
    
    D 1 Reply Last reply
    0
    • D Dhiraj kumar Saini

      My following code is unable to upload/write file on the server. Please tell me whats wrong or how can i upload it in a different way on an HTTP Server. I am using MFC.

      INTERNET_BUFFERS BufferIn = {0};
      DWORD dwBytesRead;
      DWORD dwBytesWritten;
      BYTE pBuffer[1024]; // Read from file in 1K chunks
      BOOL bRead, bRet;
      HANDLE hFile;

      HINTERNET hSession = InternetOpen(NULL,
                                        INTERNET\_OPEN\_TYPE\_PRECONFIG,
                                        NULL,
                                        NULL,
                                        0);
      HINTERNET hConnection = InternetConnect(hSession, 
                                              \_T("www.crmpanel.com"),  // Server
                                              INTERNET\_DEFAULT\_HTTP\_PORT,
                                              NULL,     // Username
                                              NULL,     // Password
                                              INTERNET\_SERVICE\_HTTP,
                                              0,        // Synchronous
                                              NULL);    // No Context
      
      
      
      
       BufferIn.dwStructSize = sizeof( INTERNET\_BUFFERS );
      
       HINTERNET hRequest = HttpOpenRequest(hConnection,
      										\_T("PUT"),
      										\_T("cp3/wn\_fupload-oo.php"),
      										NULL,
      										NULL,
      										NULL,
      										0,
      										0);
       if (!hRequest)
       {
         //printf("Failed to open request handle: %lu\\n", GetLastError ());
      	 MessageBox(\_T("Failed to open request handle:"),NULL,MB\_OK);
         return ;
       }
      
      //HttpAddRequestHeaders(hRequest, \_T("Content-Type: multipart/form-data;sid=52501;"), -1, HTTP\_ADDREQ\_FLAG\_ADD);
      
      
      
      
       hFile = CreateFile (\_T("c:\\\\Image1.gif"),
      					GENERIC\_READ,
      					FILE\_SHARE\_READ,
      					NULL,
      					OPEN\_EXISTING,
      					FILE\_ATTRIBUTE\_NORMAL,
      					NULL);
      
       if (hFile == INVALID\_HANDLE\_VALUE)
       {
         //printf("\\nFailed to open local file.");
          MessageBox(\_T("Failed to open local file"),NULL,MB\_OK);
         return ;
       }
      
      
      
       BufferIn.dwBufferTotal = GetFileSize(hFile, NULL);
       MessageBox(\_T("File size is"),NULL,MB\_OK);
       //printf ("File size is %d\\n");//, BufferIn.dwBufferTotal );
      
      // CString h = \_T("Content-Type: multipart/form-data");
      
      //CString s = \_T("filename=Iamge1.xml&filetype=gif&filesize=70204&sid=52501&csesid=111");
      
      //BOOL bo = HttpSendRequest(hRequest,(LPCTSTR)&h, h.GetLength(),(LPVOID)&s ,s.GetLength());
      
      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Dhiraj kumar Saini wrote:

      My following code is unable to upload/write file on the server.

      And? How are we supposed to offer any suggestions if you don't tell us what is wrong, what you've tried, etc?

      "Love people and use things, not love things and use people." - Unknown

      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups