title: application/zip winsock c++
body: <p>I'm trying to make a GET url request, response content type is "application/zip," but I'm having trouble outputting the content to an appropriate/readable zip file, here is my code, as you can tell, I'm trying to write out to 2 different files, neither are working, both are unreadable as zip files:</p>
  
  <pre><code>bool ionMyPlugin::downloadRact(int goodsId) {
      goodsId = 36028;
      WSADATA wsaData;
      SOCKET Socket;
      SOCKADDR_IN SockAddr;
      int lineCount = 0;
      int rowCount = 0;
      struct hostent *host;
      locale local;
      char buffer[10000];
      int i = 0;
      int nDataLength;
      string website_HTML;
  
      // website url
      string url = "eihome.eihoo.com";// / api ? mod = rayvr&amp;app = apigoods&amp;act = index&amp;store_id = 34837 &amp; secret_key = 8d410f7007b47e76c227cfa8c282c5f5&amp;add_time = 1474877868 &amp; company = eihome%E6%B5 % 8B % E8%AF % 95 % E4%BC % 81 % E4%B8 % 9A &amp; sign = fd53cce56c4eb88e356d58f19c337e79";
      string url2 = "?mod=rayvr&amp;app=apigoods&amp;act=download&amp;store_id=34837&amp;goods_id=36010&amp;secret_key=8d410f7007b47e76c227cfa8c282c5f5&amp;add_time=1474877868&amp;company=eihome%E6%B5%8B%E8%AF%95%E4%BC%81%E4%B8%9A&amp;sign=fd53cce56c4eb88e356d58f19c337e79";// +goodsId;
  
      //HTTP GET
      string get_http = "GET /" + url2 + " HTTP/1.1\r\nHost: " + url + "\r\nConnection: close\r\n\r\n";
  
      if (WSAStartup(MAKEWORD(2, 2), &amp;wsaData) != 0){
          cout &lt;&lt; "WSAStartup failed.\n";
          system("pause");
      }
  
      Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      host = gethostbyname(url.c_str());
  
      SockAddr.sin_port = htons(80);
      SockAddr.sin_family = AF_INET;
      SockAddr.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr);
  
      if (connect(Socket, (SOCKADDR*)(&amp;SockAddr), sizeof(SockAddr)) != 0){
          cout &lt;&lt; "Could not connect";
          system("pause");
      }
  
      // send GET / HTTP
      send(Socket, get_http.c_str(), strlen(get_http.c_str()), 0);
      ofstream myfile;
      fstream myfile2("myfile2.zip", ios::out | ios::binary);
      myfile.open("example.zip", std::ios_base::binary);
      // recieve html
      int countWS = 0;
      while ((nDataLength = recv(Socket, buffer, 10000, 0)) &gt; 0){
          int i = 0;
          while (buffer[i]){//buffer[i] &gt;= 32 || buffer[i] == '\n' || buffer[i] == '\r'){
              myfile &lt;&lt; buffer[i];
              myfile2.write(reinterpret_cast&lt;char *&gt; (&amp;buffer[i]), sizeof(buffer[i]));
              website_HTML += buffer[i];// &gt;&gt; 8);
              //website_HTML += ((buffer[i] &lt;&lt; 8) &gt;&gt; 8);
  
              i += 1;
              if (i &gt;= nDataLength)
                  break;
          }
      }
  
      closesocket(Socket);
      WSACleanup();
      return false;
  }
  </code></pre>