# .NET and More > ASP.NET And ASP.NET Core >  rest sharp code is not working

## erum_mirza

below code is not working giving me an error "method not allowoed"



```
 
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*****************************/
```

----------


## si_the_geek

_Thread moved from the CodeBank forum (which is for working examples, not questions) to the ASP.NET And ASP.NET Core forum._

----------


## danasegarane

If you are getting the method is not allowed this mean that the API is not having that method. 



```
// IRestResponse apiresponse =  apiclient.Execute(request);
```

Looks like you are doing a post method to create element which may not supported .

----------


## GRichG

Did you get this resolved?

----------

