question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Receive MethodNotAllowed in v107

See original GitHub issue

I am attempting a POST request in v107 that used to work before v107. See https://stackoverflow.com/questions/70686539/v107-getting-status-code-of-methodnotallowed-on-a-post-request-that-used-to-work for details. As suggested by Alexey there I have re-written some code and now I get an exception with MethodNotAllowed, rather than a response with status - MethodNotAllowed.

To Reproduce Reworked Code:

//constructor
public MerlinServiceBase()
{
    GetCreds();
    _authClient = new RestClient(_authUrl);
    _authClient.Authenticator = new HttpBasicAuthenticator(_authClientId, _authClientSecret);
}

private async System.Threading.Tasks.Task<string> GetAuthTokenAsync()
{
     var request = new RestRequest().AddParameter("grant_type", "client_credentials");
     var response = await _authClient.PostAsync<Dictionary<string, string>>(request);
     return response["access_token"];
}

Expected behavior I expected to get an auth token

Stack trace

System.Net.Http.HttpRequestException
  HResult=0x80131500
  Message=Request failed with status code MethodNotAllowed
  Source=RestSharp
  StackTrace:
   at RestSharp.RestClientExtensions.<PostAsync>d__11`1.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at RentalWebClient.V3.QA.Automation.UI.MerlinServiceBase.<GetAuthTokenAsync>d__10.MoveNext() in C:\Source\OpenTech\Kiosk\Ota.Kiosk.RentalWebClient.V3.QA.Automation\RentalWebClient.V3.QA.Automation.UI\_Merlin API\Merlin_ServiceBase.cs:line 87

  This exception was originally thrown at this call stack:
    [External Code]
    RentalWebClient.V3.QA.Automation.UI.MerlinServiceBase.GetAuthTokenAsync() in Merlin_ServiceBase.cs

Desktop (please complete the following information):

  • OS: Windows 10
  • .NET Framework 4.7.2

Additional context Please let me know what other details I could add.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
dcdrapercommented, Jan 18, 2022

We use Amazon Cognito with client_credentials: https://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html

I am still trying stuff here and there, learning about and finding my way around the the new and old layouts of the client and response objects. A minor thing I noticed is that Resource is set to “” instead of null on the new RestRequest object, but moving “/token” to there from my base url seemed to not help (or hurt) at all.

0reactions
dcdrapercommented, Jan 19, 2022

That fixed it 😃 Thank you so much for spending so much of your valuable time on it, it is appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

v107 Getting Status Code of MethodNotAllowed on a Post ...
I am trying to get an auth token using RestSharp v107 and I cannot figure out how to make it work. I have...
Read more >
How to Fix the HTTP 405 Method Not Allowed Error
It's an HTTP response status code that indicates that the request method is known by the server but is not supported by the...
Read more >
method not allowed - Microsoft Q&A
while working with identity server . i used restsharp .its giving me an error "method not allowed" as a response, can any body...
Read more >
Error handling
It means that there's no RestResponse to set the response status to error. We decided to throw an exception when such a request...
Read more >
How to Fix HTTP Error 405 Method Not Allowed
When a website displays the 405 Method Not Allowed notification, it indicates a Hypertext Transfer Protocol (HTTP) error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found