title: How to simulate the browser to login in https website using c++ based on Linux?
body: <p>everybody,my goal is logging in a https website and downloading webpage using C++ background service program based on Linux.
    Detail needs is follow:
    (1)connect to "<a href="https://www.space-track.org/auth/login" rel="nofollow">https://www.space-track.org/auth/login</a>"
    (2)enter username and password in order to login in successful
    (3)post some formdata to this website
    (4)downloading the webpage.</p>
  
  <p>Now,my method is using MFC::CInternetSession(code is follow. It is in the MS-Windows),but it's not successful. there must exist some problems in the codes. I hope you can help me solve the problem. maybe you can come up with better solutions using C++ to simulate the browser based on Linux. thank you very much！</p>
  
  <pre><code>Url = "https://www.space-track.org/auth/login/";
  
  nPort = INTERNET_DEFAULT_HTTP_PORT;
  CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded");
  
  if (AfxParseURL(Url,dwSeviceType,strServerName,strTarget,nPort) == 0)
      return false;
  
  CInternetSession sess;
  
  sess.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,1000*20);
  sess.EnableStatusCallback(TRUE);
  
  CHttpConnection* pHttpConnect = sess.GetHttpConnection(strServerName,nPort);
  
  CHttpFile* pHttpFile = pHttpConnect-&gt;OpenRequest(CHttpConnection::HTTP_VERB_POST,
      strTarget,NULL,1,NULL,NULL,INTERNET_FLAG_SECURE);
  
  
   CString strUserName = "*****";
   CString strPassword = "*****";
   CString strUserinfo;
   strUserinfo.Format(_T("identity=%s&amp;password=%s"),strUserName,strPassword);
  
  try
  {
      BOOL bResult =pHttpFile-&gt;SendRequest(strHeaders,(LPVOID)(LPCTSTR)strUserinfo,strUserinfo.GetLength()* sizeof(TCHAR));
      //BOOL bResult =pHttpFile-&gt;SendRequest(strHeaders);
  }
  catch (CInternetException* pException)
  {
      pException-&gt;m_dwError;
      pException-&gt;Delete();
  }
  pHttpFile-&gt;SetReadBufferSize(2048);
  CString str;
  CString strGetData;
  while(pHttpFile-&gt;ReadString(strGetData))
  {
      str +="\r\n";
      str +=strGetData;
  }
  CString fileName("index.html");
  CFile file(fileName,CFile::modeCreate | CFile::modeWrite);
  file.Write(str,str.GetLength());
  file.Close();
  pHttpFile-&gt;Close();
  delete pHttpFile;
  pHttpConnect-&gt;Close();
  delete pHttpConnect;
  sess.Close();
  return TRUE;
  </code></pre>