c # how to use the POST method with Restsharp

1

I have a code to login, but when I send the correct data the API continues to send the code "Unauthorized".

The code is as follows:

var client = new RestClient("link");
var request = new RestRequest("/v1.5/auth/authenticate", Method.POST);
request.RequestFormat = DataFormat.Json;
string user = "{\"nif\":\"15551\", \"nome\":\"teste\", \"password\":\"teste2\", \"loja\": 17 }";
request.AddParameter("text/json", user, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
    
asked by anonymous 08.02.2017 / 15:23

1 answer

1

My problem was not having the "user" before the start of the JSON code and the ADDParameter was wrong.

var client = new RestClient("link");
var request = new RestRequest("/v1.5/auth/authenticate", Method.POST);
request.RequestFormat = DataFormat.Json;
string user = "{\"user\":{\"nif\":\"15551\", \"nome\":\"teste\", \"password\":\"teste2\", \"loja\": 17 }}";
request.AddParameter("application/json; charset=utf-8", user, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
    
08.02.2017 / 16:14