2011-10-18 6 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 사이트에서 나는 많은 사이트를 시도했다. 그래서 나는 그 사이트의 문제점을 생각하지 않는다.

+0

당신은 당신이하지 않는, URL에 'https'로 지정합니까? 디버거를 사용하여 코드를 단계별로 실행할 때 무엇을 볼 수 있습니까? 응답에는 무엇이 있습니까? –

+0

인증서가 허용되지만 httpres의 값은 여전히 ​​null로 설정됩니다. – prasanth

답변

0

문제가있는 사람이 https가 200 (OK)으로 응답했지만 http가 302 (Found)로 응답했기 때문에 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

관련 문제