below code is not working giving me an error "method not allowoed"
Code:
using RestSharp;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48
| (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
var client = new RestClient("https://localhost:4009/connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded"
, "grant_type=client_credentials&client_id="m2m2"&client_secret="uykykjh"&audience=Api&scope=Api", ParameterType.RequestBody);
IRestResponse response =await client.ExecuteAsync(request);
var result = JsonConvert.DeserializeObject<ResponseMessage>(response.Content);
//api call
//the same code with microsoft httpclient api works here
HttpClient apiclient2 = new HttpClient();
apiclient2.DefaultRequestHeaders.Authorization
= new AuthenticationHeaderValue("Bearer", result.access_token);
var result2= await apiclient2.GetAsync("https://localhost:44347/weatherforecast/notedited/1");
var content = await result2.Content.ReadAsStringAsync();
/*************this code is not working*****************************/
// api call
var apiclient = new RestClient("https://localhost:44347/weatherforecast/notedited/1");
var apirequest = new RestRequest(Method.GET);
apirequest.AddHeader("content-type", "application/json");
apirequest.AddHeader("authorization", string.Format( "Bearer {0}" , result.access_token));
// IRestResponse apiresponse = apiclient.Execute(request);
//the error appears here "Method not allowed"******************/
IRestResponse apiresponse = await apiclient.ExecuteAsync(request);
/*************this code is not working ends*****************************/