Good Day peeps,
I have been stuck at this issue for around 6 hours and i can't figure out what's wrong with it.Firstly, i'm trying to send a Request to an server end point which requires some form of basic auth as json. But the when it hits the method "Execute" it throws an null reference exception. Not the code below:
SomeObjectClass someObject = new SomeObjectClass();
RestRequest request = new RestRequest();
request.Method = Method.POST;
request.JsonSerializer = new CustomJsonSerializer();
request.RequestFormat = DataFormat.Json;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
var client = new RestClient();
client.BaseUrl = "https://www.somewebsite.com/someapi/something";
client.Authenticator = new HttpBasicAuthenticator("username","password");
client.AddHandler("application/json", new CustomerSerializer);
request.AddBody(someObject);
var result = client.Execute<dynamic>(request);
return result;
And i've been getting NullReferenceException :
at RestSharp.HttpBasicAuthenticator.<Authenticate>b__0(Parameter p)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at RestSharp.HttpBasicAuthenticator.Authenticate(IRestClient client, IRestRequest request)
at RestSharp.RestClient.AuthenticateIfNeeded(RestClient client, IRestRequest request)
at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)
at RestSharp.RestClient.Execute(IRestRequest request)
at RestSharp.RestClient.Execute[T](IRestRequest request)
My initial guess will be my lack of understanding of ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; }); caused this problem, but i can't really pin point it. I've been spending quite some time on this issue and resort to posting the problem, it'll be really appreciated if some expert can provide an answer on this.