0
Good night people. I’m new to the C# world and I’m having the following problem using a C# code that makes an authentication request using Restsharp. This code was generated/exported from a request in Postman, so I know the request works.
It’s not a local url, it’s a login request in my production environment, I just changed the parameters, url, user and password.
using System;
using RestSharp;
public class Program
{
public static void Main()
{
var client = new RestClient("https://minhaurldelogin/api/v3/login/");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\n \"email\": \"[email protected]\",\n \"senha\": \"M1NH4C3nha\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.ErrorException);
}
}
Printing the response.ErrorException
I have following mistake
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Net.HttpWebRequest.set_ServerCertificateValidationCallback(RemoteCertificateValidationCallback value)
at RestSharp.Http.ConfigureWebRequest(String method, Uri url)
at RestSharp.Http.ExecuteRequest(String httpMethod, Action`1 prepareRequest)
at RestSharp.Http.PostPutInternal(String method)
at RestSharp.Http.AsPost(String httpMethod)
at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method)
at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was:
MyComputer
I don’t really know what I’m doing wrong. I appreciate the help.