title: use POST to send a file using c++
body: <pre><code>#include &lt;winsock2.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #pragma comment(lib,"ws2_32.lib")
  using namespace std;
  int main (){
      WSADATA wsaData;
      if (WSAStartup(MAKEWORD(2,2), &amp;wsaData) != 0) {
          cout &lt;&lt; "WSAStartup failed.\n";
          system("pause");
          return 1;
      }
      SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
      struct hostent *host;
      host = gethostbyname("127.0.0.1");
      SOCKADDR_IN SockAddr;
      SockAddr.sin_port=htons(80);
      SockAddr.sin_family=AF_INET;
      SockAddr.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr);
      cout &lt;&lt; "Connecting...\n";
      if(connect(Socket,(SOCKADDR*)(&amp;SockAddr),sizeof(SockAddr)) != 0){
          cout &lt;&lt; "Could not connect";
          system("pause");
          return 1;
      }
      cout &lt;&lt; "Connected.\n";
  
  
      char header[]="POST /xampp/tests/file/upload_file.php HTTP/1.1\r\nHost: 127.0.0.1 \r\n Content-Disposition: form-data\r\n uname=sase \r\n  Connection: close\r\n\r\n ";
  
      send(Socket,header, strlen(header),0);
      char buffer[100000];
      int nDataLength;
      while ((nDataLength = recv(Socket,buffer,100000,0)) &gt; 0){        
          int i = 0;
          while (buffer[i] &gt;= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
              cout &lt;&lt; buffer[i];
              i += 1;
          }
      }
      closesocket(Socket);
          WSACleanup();
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>i have this code from the internet, how do i make it send a file using the POST method. <br> I was at this for more than 5 hours. Please help. Also is there another way of sending http-headers/uploading a with c++ without using other libraries.</p>