title: Windows Http Server API HTTPS Server
body: <p>I want to setup a HTTPS Server with Windows Server API in c++, I used the example code, it is working fine with HTTP, but I just can not make it to work with HTTPS.</p>
  
  <p>(I do not want client side SSL I only one it to be HTTPS ) </p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa364640(v=vs.85).aspx</a></p>
  
  <p>I tryed with "HttpSetServiceConfiguration HTTP_SERVICE_CONFIG_SSL_SET" here is my try:</p>
  
  <pre><code>PHTTP_SERVICE_CONFIG_SSL_SET p_ssl_settings = new HTTP_SERVICE_CONFIG_SSL_SET();
  p_ssl_settings-&gt;KeyDesc.pIpPort = new SOCKADDR();
  inet_pton(AF_INET, "0.0.0.0", p_ssl_settings-&gt;KeyDesc.pIpPort);
  p_ssl_settings-&gt;ParamDesc.SslHashLength = 40;
  p_ssl_settings-&gt;ParamDesc.pSslHash = "dec5a1a952967a613f27dec98ab78a248cd9f782";
  p_ssl_settings-&gt;ParamDesc.AppId = {0x4dbfb575, 0xe1ef, 0x4239,{0x9a, 0x1d, 0xe9, 0x4c, 0xf8, 0x4d, 0xc2, 0x2d}};
  p_ssl_settings-&gt;ParamDesc.pSslCertStoreName = nullptr;
  p_ssl_settings-&gt;ParamDesc.DefaultCertCheckMode = 0;
  p_ssl_settings-&gt;ParamDesc.DefaultRevocationFreshnessTime = 0;
  p_ssl_settings-&gt;ParamDesc.DefaultRevocationUrlRetrievalTimeout = 0;
  p_ssl_settings-&gt;ParamDesc.pDefaultSslCtlIdentifier = nullptr;
  p_ssl_settings-&gt;ParamDesc.pDefaultSslCtlStoreName = nullptr;
  p_ssl_settings-&gt;ParamDesc.DefaultFlags = HTTP_SERVICE_CONFIG_SSL_FLAG_NEGOTIATE_CLIENT_CERT;
  
  
  const auto retcode = HttpSetServiceConfiguration(
      hReqQueue,
      HTTP_SERVICE_CONFIG_ID::HttpServiceConfigSSLCertInfo,
      p_ssl_settings,
      sizeof HTTP_SERVICE_CONFIG_SSL_SET,
      nullptr
  );
  
  if (retcode != NO_ERROR) {
      throw exception(string("HttpSetServiceConfiguration failed with " + to_string(retcode)).c_str());
  }
  </code></pre>
  
  <p>But when I run the code get error:87 which is the bad parameter error but to me the parameters seams fine. </p>
  
  <p>On this web page it is mentiond that the HANDLE must be zero: 
  (ServiceHandle [in] Reserved. Must be zero.)</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364503(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/aa364503(v=vs.85).aspx</a></p>
  
  <p>but when I pass a nullptr or a HANDLE variable which value is zero I get error code '6' (The handle is invalid.) so I am not sure</p>
  
  <p>I tryed with "netsh http add sslcert ipport=0.0.0.0:50001 certhash=de... appid{...}</p>
  
  <p>but I can not get this right because I get error 1312:
  (my be my appid is bad, but I dont know how to get it for my visual studio c++ .exe)
  A specified logon session does not exist. It may already have been terminated.</p>
  
  <p>I tryed with "<a href="https://localhost:50001/" rel="nofollow noreferrer">https://localhost:50001/</a>" as an URL.</p>
  
  <p>How can I do it right with c++ "HttpSetServiceConfiguration" or netsh?</p>