So ignorieren Sie die Zertifikatsprüfung bei SSL

Ich versuche, eine Möglichkeit zu finden, die Zertifikatprüfung zu ignorieren, wenn ich eine HTTP-Ressource anfordere. Bisher habe ich im Internet einen hilfreichen Artikel gefunden.

Aber ich habe immer noch ein Problem. Bitte überprüfen Sie meinen Code. Ich verstehe nur nicht, was der Code machtServicePointManager.ServerCertificateValidationCallback bedeuten.

Wann wird diese Delegate-Methode aufgerufen? Und noch eine Frage, an welcher Stelle soll ich diesen Code schreiben? VorServicePointManager.ServerCertificateValidationCallback ausführen oder vorherStream stream = request.GetRequestStream()?

public HttpWebRequest GetRequest()
{
    CookieContainer cookieContainer = new CookieContainer();

    // Create a request to the server
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_remoteUrl);

    #region Set request parameters

    request.Method = _context.Request.HttpMethod;
    request.UserAgent = _context.Request.UserAgent;
    request.KeepAlive = true;
    request.CookieContainer = cookieContainer;
    request.PreAuthenticate = true;
    request.AllowAutoRedirect = false;

    #endregion

    // For POST, write the post data extracted from the incoming request
    if (request.Method == "POST")
    {
        Stream clientStream = _context.Request.InputStream;
        request.ContentType = _context.Request.ContentType;
        request.ContentLength = clientStream.Length;

        ServicePointManager.ServerCertificateValidationCallback = delegate(
            Object obj, X509Certificate certificate, X509Chain chain, 
            SslPolicyErrors errors)
            {
                return (true);
            };

            Stream stream = request.GetRequestStream();

            ....
        }

        ....

        return request;
    }
}   

Antworten auf die Frage(11)

Ihre Antwort auf die Frage