locked
RestClient - how to add SSL RRS feed

  • Question

  • User-1852975005 posted

    Hi, I have the below code;

    I am new to this and I dont now if I am going about this in the right way at all.

    The line - 

    Client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

    Gives the below error.

    Severity

    Code

    Description

    Project

    File

    Line

    Suppression State

    Error

    CS0136

    A local or parameter named 'sender' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter

    restClient_0

    C:\Users\Administrator\Desktop\VP-O\VP-0-REST-Client-master\VP-0-REST-Client-master\restClient_0\Form1.cs

    27

    Active

    A dum question what is Sender and what is it asking for?

    private void cmdGO_Click(object sender, EventArgs e)

            {

     

                var Client = new RestClient("https://xx.xx.xx.xx.:8443/xxxx/xxxxxx/work/");

     

                Client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;

     

                var request = new RestRequest();

     

                request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxx");

     

                //Execute Request

                IRestResponse response = Client.Execute(request);

     

                txtResponse.Text = response.Content;

     

            }

    Thanks,

    Tuesday, February 18, 2020 9:02 AM

All replies

  • User753101303 posted

    Hi,

    Use (request, certificate, chain, sslPolicyErrors) or whatever. "sender" is already an argument for cmdGO_Click. Not 100% sure. You could check the object type. I would expect this to be the object that triggers the validation (here likely the RestRequest in case you want to use it).

    Even if you have to bypass validation errors, you could to still do some checks rather than accepting it unconditionally...

     

    Tuesday, February 18, 2020 9:21 AM
  • User-474980206 posted

    This is kind of a silky restriction in c# (they thought it would reduce bugs). Even in a new scope you can not use a variable name that exists in the outer scope. That just means you need to rename one of you sender varaiable.

    Tuesday, February 18, 2020 3:08 PM