title: C# WebRequest (400) Bad Request on second call
body: <p>I'm trying to check our SSL certificates with a program but i have an issue; i can not use second HttpWebRequest because of something which i don't know. I supposed it's a cache problem and used all of the no-cache codes that i know. As you can see servers are in our private subnet and 1 server has a lot of IIS application. Because of that i'm changing "request.Host" variable to our matching IIS bindings for open the sites. Always second one is not working but first one works well. What is the problem?      </p>
  
  <pre><code>            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://" + "10.10.11.100");
              request.AllowAutoRedirect = false;
              request.Host = "www.xxx.com";
              request.Timeout = 30 * 1000;
              request.Headers.Add("Cache-Control", "no-cache");
              request.Referer = null;
              request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
              using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
              {
                  //retrieve the ssl cert and assign it to an X509Certificate object
                  X509Certificate cert = request.ServicePoint.Certificate;
                  //convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
                  X509Certificate2UI.DisplayCertificate(new X509Certificate2(cert));
              }
              HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create("https://" + "10.10.11.100");
              request2.AllowAutoRedirect = false;
              request2.Host = "www.yyy.com";
              request2.Timeout = 30 * 1000;
              request2.Headers.Add("Cache-Control", "no-cache");
              request2.Referer = null;
  
              request2.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
              using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse())
              {
                  //retrieve the ssl cert and assign it to an X509Certificate object
                  X509Certificate cert2 = request2.ServicePoint.Certificate;
                  //convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
                  X509Certificate2UI.DisplayCertificate(new X509Certificate2(cert2));
              }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>        The remote server returned an error: (400) Bad Request.
  </code></pre>
  
  <p>Exception Line:</p>
  
  <pre><code>using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse()) 
  </code></pre>
  
  <p>Status: ProtocolError</p>
  
  <p>InternalStatus: RequestFatal   </p>