mohan21
mohan21

Reputation: 55

c# Program error "the requested security protocol is not supported"

I used below code

try
{
    ServicePointManager.ServerCertificateValidationCal  lback = delegate { return true; };
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;

    WebRequest req = WebRequest.Create(site);
    req.ContentType = "application/x-www-form-urlencoded";
    req.Method = "POST";
    byte[] bytes = Encoding.UTF8.GetBytes("data=" + "null");
    req.ContentLength = bytes.Length;
    Stream os = req.GetRequestStream();
    os.Write(bytes, 0, bytes.Length);
    os.Close();
    WebResponse resp = req.GetResponse();
    StreamReader sr = new StreamReader(resp.GetResponseStream());

    MessageBox.Show(sr.ReadToEnd().Trim());
}
catch (Exception exc)
{
    MessageBox.Show(exc.Message.ToString());
}

The program run in my computer without error but when run in my customer`s computer show below error "the requested security protocol is not supported"

in continue I change code to below

try
{
    WebRequest req = WebRequest.Create(site);
    req.ContentType = "application/x-www-form-urlencoded";
    req.Method = "POST";
    byte[] bytes = Encoding.UTF8.GetBytes("data=" + "null");
    req.ContentLength = bytes.Length;
    Stream os = req.GetRequestStream();
    os.Write(bytes, 0, bytes.Length);
    os.Close();
    WebResponse resp = req.GetResponse();
    StreamReader sr = new StreamReader(resp.GetResponseStream());


    MessageBox.Show(sr.ReadToEnd().Trim());
}
catch (Exception exc)
{
    MessageBox.Show(exc.Message.ToString());
}

but again error.

my customer`s computer is win7 by donNet 4.

Upvotes: 1

Views: 3239

Answers (1)

mohammad amini nasab
mohammad amini nasab

Reputation: 76

You set below code and test

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

Upvotes: 1

Related Questions