2011-10-18 35 views
1

ウェブサイトがダウンしている場合にアラートを送信するためにWindowsアプリケーションを作成しようとしています。SSLサイトのhttp応答コードasp

HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(textBox1.Text); 
httpReq.AllowAutoRedirect = false; 

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse(); 

if (httpRes.StatusCode == HttpStatusCode.Found) 
{ 
    MessageBox.Show("It works."); 
} 
else 
{ 
    MessageBox.Show("Not able to ping"); 
} 
httpRes.Close(); 

は、それがうまく働いたが、私はそれdidntの仕事(HTTPS)SSLサイトの同じことをやってみたかったとき、私はそれを見て、

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); 

それでも、任意の応答を取得することはできませんイム追加しましたhttpsのサイトから、私は多くのサイトを試したので、私はそのサイトの問題は考えていません.netの初心者は助けに感謝しています。

+0

あなたがそうしない、URLに「https」のを指定するのですか?デバッガを使用してコードをステップ実行すると、何が表示されますか?レスポンスには何がありますか? –

+0

証明書は受け入れられますが、httpresの値は引き続きnullに設定されています。 – prasanth

答えて

0

httpが302(Found)で応答していたのに対し、httpsは200(OK)で応答していましたので、私は自分の状態を200に変更して魅力的に機能しました。作業コードに興味のある人のために、ここにある

 public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) 
    { 
     return true; 
    } 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); 
     HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(textBox1.Text); 
     httpReq.AllowAutoRedirect = false; 


      HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse(); 

      if (httpRes.StatusCode == HttpStatusCode.OK || httpRes.StatusCode==HttpStatusCode.Found) 
      { 
       MessageBox.Show("It works."); 
      } 
      else 
      { 
       MessageBox.Show("Not able to ping"); 
      } 
      httpRes.Close(); 
     } 

よろしく、 Prasanth

関連する問題