2016-04-27 13 views
0

SSL証明書をプログラムでチェックしようとしていますが、問題があります。私は知らない何かのために2番目のHttpWebRequestを使うことはできません。私はそれがキャッシュの問題だと思って、私が知っているすべてのノー・キャッシュ・コードを使いました。ご覧のように、サーバーはプライベートサブネットにあり、1台のサーバーには多くのIISアプリケーションがあります。そのため、私はサイトを開くための私たちの一致するIISバインディングに "request.Host"変数を変更しています。常に2番目のものは動作しませんが、最初のものはうまくいきます。何が問題ですか?C#WebRequest(400)Bad call second call

  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)); 
      } 

エラー:

 The remote server returned an error: (400) Bad Request. 

例外ライン:

using (HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse()) 

ステータス:ProtocolErrorの

InternalStatus:RequestFatal

+0

注文を交換して、2番目のサーバーの問題であるかどうか確認しましたか? – WillG

+1

はい、私はしました。私が注文を変えれば、最初のものは前と同じように働いています。 –

答えて

0

私は私の問題を解決しました。問題はキープアライブ属性であり、その2番目のSSL接続が正しく初期化されなかったためです。この行をリクエストに追加する必要があります。

 request.KeepAlive = false;