1

I have an endpoint that I connect to by RestSharp sending a json, and it works correctly for me is this:

 public void GetToken()
    {
       
        var client = new RestClient("UrlEndpoint");
        var req = new RestRequest(Method.POST);
        req.AddHeader("Content-Type", "application/json");
        req.AddParameter("application/json", JsonConvert.SerializeObject(new { user = "usuario", password = "password" }), ParameterType.RequestBody);
        var res = client.Execute(req);
    }

Now I need to consume another endpoint, but its Content-Type is application / x-www-form-urlencoded, I did this:

public void GetResponse()
    {
        var client = new RestClient("https://sdx-identityserver-qa.azurewebsites.net/connect/token");
        var req = new RestRequest(Method.POST);
        req.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        req.AddParameter("application/x-www-form-urlencoded", "client_id=sdx_corefin_pel&client_secret=8c6a56d2-bd3a-4e83-a578-cb78c6e66f19&grant_type=client_credentials", ParameterType.RequestBody);
   
      
        var res = client.Execute(req);
    }

but it throws me a statuscode 0 and an error: "Unable to write data from to the transport connection: An existing connection was forced to break by the remote host."

I also tried this:

 public void GetResponse()
    {
        var client = new RestClient("https://sdx-identityserver-qa.azurewebsites.net/connect/token");
        var req = new RestRequest(Method.POST);
        req.AddHeader("Content-Type", "application/x-www-form-urlencoded");
       
       req.AddParameter("client_id", "sdx_corefin_pel");
       req.AddParameter("client_secret", "8c6a56d2-bd3a-4e83-a578-cb78c6e66f19");
       req.AddParameter("grant_type", "client_credentials");
      
        var res = client.Execute(req);
    }

But the answer is the same error,

In postman it works well:

PostmanEndpoint

I have added the variable "scope" but it does not work either, I have added in each req.AddParameter, ParameterType.GetOrPost but the answer is the same.

Thanks for Your Help.

0 Answers0