title: Dev C++ Wininet Upload file using HTTP
body: <p>I want to upload "C:\test.txt" to webserver, when I am running program, file is not uploading and I am not getting any error.</p>
  
  <p><a href="http://student114.110mb.com/upload.cpp.txt" rel="nofollow noreferrer">the complete C++ code can be find here</a> </p>
  
  <p>and php code on webserver can be find here: "<a href="http://student114.110mb.com/upload.txt" rel="nofollow noreferrer">http://student114.110mb.com/upload.txt</a>" 
  or 
  "<a href="http://student114.110mb.com/upload.php" rel="nofollow noreferrer">http://student114.110mb.com/upload.php</a>"</p>
  
  <p>kindly help me where I am doing wrong</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;wininet.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;iostream&gt;
  
  #pragma comment(lib,"wininet.lib")
  
  using namespace std;
  
  int main()
  {
  
      static TCHAR frmdata[] = "-----------------------------7d82751e2bc0858\nContent-Disposition: form-data; name=\"uploadedfile\"; filename=\"C:\test.txt\"\nContent-Type: text/plain\n\nfile contents  here\n-----------------------------7d82751e2bc0858--"; 
      static TCHAR hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858"; 
  
      HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
       if(hSession==NULL)
      {
       cout&lt;&lt;"Error: InternetOpen";  
      }
  
  
      HINTERNET hConnect = InternetConnect(hSession, _T("localhost"),INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
       if(hConnect==NULL)
      {
       cout&lt;&lt;"Error: InternetConnect";  
      }
  
      HINTERNET hRequest = HttpOpenRequest(hConnect, (const char*)"POST",_T("upload.php"), NULL, NULL, (const char**)"*/*\0", 0, 1);
      if(hRequest==NULL)
      {
       cout&lt;&lt;"Error: HttpOpenRequest";  
      }
  
      BOOL sent= HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));
      if(!sent)
      {
       cout&lt;&lt;"Error: HttpSendRequest";
       }
  
      //close any valid internet-handles
      InternetCloseHandle(hSession);
      InternetCloseHandle(hConnect);
      InternetCloseHandle(hRequest);
  
      return 0;
  }
  </code></pre>