''RestClient' does not contain a definition for 'Execute'
I have been working on getting an api authentication to work and I am currently stuck on getting the response to execute to show up in a text box.
{
private void button1_Click(object sender, EventArgs e)
{
string user = textBoxUsername.Text;
string password = textBoxPassword.Text;
string tenant = comboBoxCompany.Text;
var client = new RestClient("https://server_name/v2/security/authenticate");
var request = new RestRequest();
request.Method = Method.Post;
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("accept", "application/json");
request.AddParameter("application/x-www-form-urlencoded",
"grantType=password&userName={{username}}&password={{password}}&tenant={{company_name}}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request); <= //error here // red line is under the 'Execute'
textBoxJson.Text = response.ToString();
}
}
public class IRestResponse
{
public bool success { get; set; }
public List<AuthenticationResponseData> result { get; set; }
}
public class AuthenticationResponseData
{
public string accesstoken { get; set; }
public string refreshtoken { get; set; }
public string accessTokenExpiresOn { get; set; }
public string refreshTokenExpiresOn { get; set; }
}
This is within a form page.
Solution 1:[1]
var request = new RestSharp.RestRequest("RESOURCE", RestSharp.Method.POST) { RequestFormat = RestSharp.DataFormat.Json }
.AddBody(BODY);
var response = Client.Execute(request);
// Handle response errors
HandleResponseErrors(response);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |